我有一个约会对象和一个预订对象。Bookings 属于 Appointments 和 Appointments has_many bookings。
我想在创建时将约会 ID 传递给 bookings.appointment_id。我怎样才能做到这一点?
*我已根据 jordanandree 的建议编辑了我的代码。现在我收到以下错误:
NoMethodError in BookingsController#new
undefined method `bookings' for nil:NilClass
在我的主页视图中,我有:
<% @appointments.each do |appointment| %>
<%= link_to "new Booking", new_appointment_booking_path(appointment)%>
<%end%>
预订控制器:
def new
@booking = @appointment.bookings.new
...
def create
@booking = @appointment.bookings.new(params[:booking])
...
路线
resources :appointments do
resources :bookings
end
非常感谢您的帮助。
耙路线:
POST /appointments/:appointment_id/bookings(.:format) bookings#create
GET /appointments/:appointment_id/bookings/new(.:format) bookings#new
GET /appointments/:appointment_id/bookings/:id/edit(.:format) bookings#edit