有没有办法简化嵌套的命名空间资源?

时间:2011-06-13 11:08:17

标签: ruby-on-rails namespaces refactoring routes

有没有更少的冗余方法来做到这一点?

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

1 个答案:

答案 0 :(得分:0)

这是嵌套资源的约定。这里所有的控制器仍然在app / controllers目录中。

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

当您需要命名空间时,通常只使用控制器的目录,例如:

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

#/admin/users