<%= form_for(@booking) do |f| %>
<% if @booking.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@booking.errors.count, "error") %> prohibited this booking from being saved:</h2>
<ul>
<% @booking.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :capacity %><br />
<%= f.text_field :capacity %>
</div>
<div class="field">
<%= f.label :date %><br />
<%= f.text_field :date %>
</div>
<h1> form for appointment </h1>
<%= f.fields_for :appointments do |builder| %>
<div class="field">
<%= builder.label :name %><br />
<%= builder.text_field :name %>
</div>
<div class="field">
<%= builder.label :mobile %><br />
<%= builder.text_field :mobile %>
</div>
<% end %>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
def create
@booking = Booking.new(params[:booking])
@appointment = @booking.appointments.build(params[:appointments])
respond_to do |format|
if @booking.save
format.html { redirect_to @booking, notice: 'Booking was successfully created.' }
format.json { render json: @booking, status: :created, location: @booking }
else
format.html { render action: "new" }
format.json { render json: @booking.errors, status: :unprocessable_entity }
end
end
end