私のモデルの要約:ユーザーには多くの予定があります。予定には多くの予約があります。予約は予定に属します。
特定の予定のすべての予約を一覧表示する特定のビュー(「users_bookings」と呼ばれる)にlink_toしようとしています。これが私が試したことです:
<% 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%>