Rails 4浅路由菜单参数未定义错误

时间:2014-01-20 11:10:40

标签: 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#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资源。

有解决这个问题的好方法吗?

1 个答案:

答案 0 :(得分:0)

即使您进行了booths#index操作,也有hall个ID,因此您可以设置@hall实例变量:

@hall = Hall.find(params[:hall_id])

然后,您可以执行以下操作:

hall_booths_path(@hall)