0

我有一个预订模型,我希望用户通过单击一个链接或另一个链接来确认/拒绝预订。我试图避免必须创建一个表单。

这是我尝试实现它的方法:

<% @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])  

如果您需要更多信息,请告诉我。先感谢您。

4

1 回答 1

1

仔细查看您的 rake 路线,您会看到它是appointment_booking和不是appointment_bookings(即s在 结尾处是no bookings)。

您还需要传入约会实例作为第一个参数。假设您的约会被调用@appointment,试试这个:

<% @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 %>
于 2012-10-04T13:44:05.063 回答