Rail Routes: Controller namespaces with constraints (subdomains)

折月煮酒 提交于 2019-12-03 03:10:04

问题


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 below:

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

Is this the right approach?


回答1:


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



来源:https://stackoverflow.com/questions/4507484/rail-routes-controller-namespaces-with-constraints-subdomains

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!