我有如下的浅路线:
resources :venues, shallow: true do
#Halls
get "hall/:id/exhibition" => "halls#exhibition", as: :exhibition
get "hall/:id/visit" => "halls#visit", as: :hall_visit
get "structure", :to => "venues#venue_structure"
resources :asset_types, :booths_tags, :tags, :uploaded_files, :events, :chats
resources :halls do
resources :webcasts
resources :booths do
resources :chats
end
end
end
问题出在下面的帮助器中,我需要提供@booth
资源作为参数:
hall_booths_path(@booth.hall)
但这并非总是可行,尤其是当它进入index
操作时,因为它没有设置@booth
资源。
有解决这个问题的好方法吗?
答案 0 :(得分:0)
即使您进行了booths#index
操作,也有hall
个ID,因此您可以设置@hall
实例变量:
@hall = Hall.find(params[:hall_id])
然后,您可以执行以下操作:
hall_booths_path(@hall)