2011-06-13 24 views
0

有沒有更少的冗餘方式來做到這一點?有什麼辦法可以簡化嵌套的命名空間資源?

resources :tournaments do 
    resources :commitments,  controller: "tournaments/commitments" 
    resources :constraints,  controller: "tournaments/constraints" 
    resources :entries,   controller: "tournaments/entries" 
    resources :buildings,  controller: "tournaments/buildings" do 
     resources :rooms,  controller: "tournaments/buildings/rooms" 
    end 
end 
+0

你問11個問題,並接受他們沒有:當你需要的名字空間,就像

resources :tournaments do resources :commitments resources :constraints resources :entries resources :buildings do resources :rooms end end 

您一般只使用你的控制器目錄。請接受關於這些問題的正確答案 - 人們會更願意提供幫助。 ..如果你這樣做,在這裏回覆我,我會幫你組織你的控制器。 – 2011-06-13 13:37:27

+0

對不起,我沒有意識到這是一個選項...我現在回去做這件事。 – tanman 2011-06-15 02:04:28

回答

0

這是嵌套資源的約定。這裏所有的控制器仍然在app/controllers目錄中。

namespace :admin do 
    resources :users 
    root :to=>"dashboards#admin" 
end 

#/admin/users 
+0

是的,我需要命名空間。例如,條目在不同的資源下使用。即使對於不一定需要命名空間的資源,我也希望它們處於應用程序的不同部分。 – tanman 2011-06-16 04:07:45

+0

然後去第二個選項。 – 2011-06-16 12:59:59