blu*_*blu 3 ruby-on-rails ruby-on-rails-3 ruby-on-rails-4
我们有一个应用程序从 Rails 3.2 升级到 4.0。
3.2版本已经roots
覆盖了routes.rb,我将其移植到新语法,但我不太确定如何处理子域约束。
在3.2中:
constraints(SubDomain) do
root to: "companies#index"
...
end
Run Code Online (Sandbox Code Playgroud)
我尝试像其他根路径一样移植它,但看起来非约束根路径上存在冲突。
这是我尝试过的:
constraints(SubDomain) do
get "/", to: "companies#index", as: :root
...
end
Run Code Online (Sandbox Code Playgroud)
和错误:
/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 with
resourcesas 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:in
add_route'
任何关于正确语法的帮助都会很棒,谢谢。
通过提供不同的名称来解决冲突
constraints(SubDomain) do
root :to => "companies#index", :as=> :subdomain_root
...
end
Run Code Online (Sandbox Code Playgroud)