开发者

Rail Routes: Controller namespaces with constraints (subdomains)

The intention is to create a subdomain to hold all the administrative function (CRUD) and the name of the subdomain is "admin". The set of controllers responsible are also organized under the namespace of "admin", i.e. the controllers are under the app/controllers/admin directory.

Ideally, the following routes should be

admin.mydomain.com/products/     
admin.mydomain.com/products/new ...

and not

admin.mydomain.com/admin/products/
admin.mydomain.com/admin/products/new ...

I would like to keep the helpers with the "admin" prefix such as:

new_admin_product
edit_admin_product

My current routing code works and it is as belo开发者_JAVA技巧w:

constraints :subdomain => "admin" do
  scope :module => "admin", :as => "admin" do
    resources :players
  end
end

Is this the right approach?


Yes, this will give you precisely what you're after in the neatest fashion I know possible.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜