這是我的config/routes.rb中文件的摘錄:命名空間資源
resources :accounts do |account|
account.resource :profile, :except => [:new, :create, :destroy]
account.resources :posts,
:collection => { :fragment => :get },
:has_many => [:comments, :likes]
# even more code
end
我想每一個嵌套的資源從加載從帳戶命名空間,例如帳戶:: PostsController代替PostsController。
使用資源:accounts, :namespace => 'account'
會嘗試加載AccountPostsController。
試圖窩結構並未真正發揮那麼好:
map.namespace :account do |account|
..
end
上面的代碼將我想要的位置加載文件,但它的命名空間添加到URL和生成路徑,所以我會有方法,如account_account_posts_url
和類似的路徑。
另一種方法是使用類似:
account.resource :profile, :controller => 'account/profile'
我真的不喜歡這個,因爲它同時涉及重複代碼,並迫使我刪除一些軌道魔法助手。
有什麼想法和建議嗎?
請參閱我的更新以瞭解應該發揮的作用。 – 2009-12-01 15:35:43