我们有一个应用程序,从Rails 3.2升级到4.0。
3.2版本的roots在整个routes.rb上都有,我将其移植到新的语法中,但我不太清楚如何处理子域约束。
在3.2中:
constraints(SubDomain) do
root to: "companies#index"
...
end我试图像其他根路径一样移植它,但是看起来在无约束的根路径上存在冲突。
以下是我尝试过的:
constraints(SubDomain) do
get "/", to: "companies#index", as: :root
...
end而错误是:
/Users/blu/.rvm/gems/ruby-2.1.7/gems/actionpack-4.0.13/lib/action_dispatch/routing/route_set.rb:430:in
add_route': Invalid route name, already in use: 'root' (ArgumentError) You may have defined two routes with the same name using the:asoption, or you may be overriding a route already defined by a resource with the same naming. For the latter, you can restrict the routes created withresourcesas explained here: http://guides.rubyonrails.org/routing.html#restricting-the-routes-created from /Users/blu/.rvm/gems/ruby-2.1.7/gems/actionpack-4.0.13/lib/action_dispatch/routing/mapper.rb:1484:inadd_route‘
任何正确的语法帮助在这里将是很好的,谢谢。
发布于 2016-05-15 18:00:58
通过给出不同的名称来解决冲突
constraints(SubDomain) do
root :to => "companies#index", :as=> :subdomain_root
...
endhttps://stackoverflow.com/questions/37178122
复制相似问题