我有一个预订模型,我希望用户通过单击一个链接或另一个链接来确认/拒绝预订。我试图避免必须创建一个表单。
这是我尝试实现它的方法:
<% @bookings.each do |booking| %>
<%= link_to "Confirm", appointment_booking_path(@appointment, booking, :status => "confirmed"), :method => :put, confirm: 'Are you sure?', :class => 'btn btn-success' %>
<%= link_to "Reject", appointment_booking_path(@appointment, booking, :status => "rejected"), :method => :put, confirm: 'Are you sure?',:class => 'btn btn-danger' %>
<%end%>
单击其中一个链接时出现此错误:
NoMethodError in BookingsController#update
undefined method `[]' for nil:NilClass
app/controllers/bookings_controller.rb:64:in `update'
预订嵌套在约会中。这是我的耙子路线:
PUT /appointments/:appointment_id/bookings/:id(.:format)
appointment_booking GET /appointments/:appointment_id/bookings/:id(.:format)
edit_appointment_booking GET /appointments/:appointment_id/bookings/:id/edit(.:format)
BookingController 更新操作:
line 64* @appointment = Appointment.find(params[:booking][:appointment_id])
@booking = Booking.find(params[:id])
如果您需要更多信息,请告诉我。先感谢您。