2014-01-20 62 views
0

我有淺路線如下圖所示:軌道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資源。

是否有解決此問題的好方法?

回答

0

即使你在booths#index行動的時候,你有你的hall ID,所以你可以設置@hall實例變量:

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

,然後,你就可以做到以下幾點:

hall_booths_path(@hall) 
+0

會你把這個置於索引操作之下?我剛剛在'@booths = Booth.all'後面試過,但找不到'@ hall'變量。 ''sidebar_menu'函數裏面有幫助器''after_action:sidebar_menu'我認爲'@hall = Hall.find(params [:hall_id])'在'index'動作中被設置,它會設置'@hall '首先我可以在幫手中使用這個,但是我得到'nil' –

+0

@PassionateDeveloper我想你應該在'before_filter'中設置'@ hall'。 –

+0

現在都在工作。謝謝!!! –