我的模型摘要:一个用户有很多约会。一个约会有很多预订。预订属于约会。
我正在尝试链接到一个特定视图(称为“users_bookings”),该视图列出了特定约会的所有预订。这是我尝试过的:
<% current_user.appointments.each do |appointment|%>
<%= link_to "view all bookings", users_bookings_appointment_booking_path(appointment)%>
<%end%>
这是我得到的错误:
undefined method `users_bookings_appointment_bookings'
附加信息:
路线:
resources :appointments do
resources :bookings do
get 'users_bookings', :on => :collection
end
end
预订控制器创建操作:
def create
@appointment = Appointment.find(params[:booking][:appointment_id])
@booking = @appointment.bookings.new(params[:booking])
预订控制器 Users_bookings 操作:
def users_bookings
@appointment = Appointment.find(params[:booking][:appointment_id])
@bookings = @appointment.bookings.all
end
users_bookings 视图:
<% @bookings.each do |booking| %>
<td><%= booking.appointment_date%></td>
<td><%= booking.start_time %></td>
<td><%= booking.end_time %></td>
<%end%>