Ruby on rails Rails 4浅路由菜单参数未定义错误
我有如下浅路线:Ruby on rails Rails 4浅路由菜单参数未定义错误,ruby-on-rails,ruby,ruby-on-rails-4,Ruby On Rails,Ruby,Ruby On Rails 4,我有如下浅路线: 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#v
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)
但这并不总是可能的,尤其是当它进入索引
操作时,因为它没有设置@booth
资源
有没有解决此问题的好方法?即使您在
展位#索引
操作中,您也有大厅
id,因此您可以设置@hall
实例变量:
@hall = Hall.find(params[:hall_id])
然后,您可以执行以下操作:
hall_booths_path(@hall)
你能把这个放在索引下吗?我刚刚在
@booths=Booth.all
之后尝试了这个,但是它找不到@hall
变量。我在侧边栏_菜单
函数中找到了助手,该函数在_操作:侧边栏_菜单后由调用,我想@hall=hall.find(params[:hall\u id])
在索引中设置
它将首先设置@hall
的操作,因此我可以在助手中使用它,但我得到了nil
somehow@PassionateDeveloper我想你应该在过滤器之前的中设置@hall
。