app/controllers/bookings_controller.rb:45:in `create'
Appointments オブジェクトと Bookings オブジェクトがあります。Bookings は Appointments に属し、Appointments は has_many の予約に属します。
:appointment_id を持つ予約オブジェクトを作成したい
これが私のコードです:
<% @appointments.each do |appointment| %>
<%= link_to "new Booking", new_appointment_booking_path(appointment)%>
<%end%>
予約管理者:
def new
@appointment = Appointment.find(params[:appointment_id])
@booking = @appointment.bookings.new
...
def create
I was missing [:booking] in line 45.
Line 45: @appointment = Appointment.find(params[:booking][:appointment_id])
@booking = @appointment.bookings.new(params[:booking])
ルート
resources :appointments do
resources :bookings
end
Bookings_form を送信すると、正しいアポイントメント ID が渡されますが、次のエラーが表示されます。
ActiveRecord::RecordNotFound in BookingsController#create
Couldn't find Appointment without an ID
予約フォーム
<%= simple_form_for(@booking) do |f| %>
<%= f.error_notification %>
<div class="form-inputs">
<%= f.input :appointment_date %>
<%= f.input :start_time %>
<%= f.input :end_time %>
<%= f.input :name %>
<%= f.input :phone_number %>
<%= f.hidden_field :appointment_id%>
<div class="form-actions">
<%= f.button :submit %>
</div>