如何将此带有子域约束的​​根路径移植到 Rails 4?

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:as option, 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 withresources as 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'

任何关于正确语法的帮助都会很棒,谢谢。

Mad*_*n S 5

通过提供不同的名称来解决冲突

constraints(SubDomain) do
  root :to => "companies#index", :as=> :subdomain_root
   ...
end
Run Code Online (Sandbox Code Playgroud)