简体   繁体   English

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

[英]How do I port this root path with a subdomain constraint to Rails 4?

We have an app an upgrading from Rails 3.2 to 4.0. 我们有一个从Rails 3.2升级到4.0的应用程序。

The 3.2 version has roots all over routes.rb, which I ported to the new syntax, but I am not quite sure how to handle the subdomain constraint. 3.2版本的roots遍布于route.rb,我将其移植到新语法中,但是我不确定如何处理子域约束。

In 3.2: 在3.2中:

  constraints(SubDomain) do
    root to: "companies#index"
    ...
  end

I tried to port it like the other root paths, but it looks like there is a conflict on the non-constrained root path. 我试图像其他根路径一样移植它,但看起来在非约束根路径上存在冲突。

Here is what I tried: 这是我尝试过的:

  constraints(SubDomain) do
    get "/", to: "companies#index", as: :root
    ...
  end

And the error: 错误:

/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 with /Users/blu/.rvm/gems/ruby-2.1.7/gems/actionpack-4.0.13/lib/action_dispatch/routing/route_set.rb:430:在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 with add_route': Invalid route name, already in use: 'root' (ArgumentError) You may have defined two routes with the same name using the 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 with add_route': Invalid route name, already in use: 'root' (ArgumentError) You may have defined two routes with the same name using the 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 with 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 with resources 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' 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 with 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 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 with资源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 with 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'

Any help on the correct syntax here would be great, thanks. 谢谢您对此处正确语法的任何帮助。

Resolve the conflict by giving a different name 通过使用其他名称解决冲突

constraints(SubDomain) do
  root :to => "companies#index", :as=> :subdomain_root
   ...
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM