gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 04:13:33 27 4
gpt4 key购买 nike

我们有一个应用程序从 Rails 3.2 升级到 4.0。

3.2 版本在 routes.rb 中有 root,我将其移植到新语法中,但我不太确定如何处理子域约束。

在 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 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

关于ruby-on-rails - 如何将带有子域约束的​​根路径移植到 Rails 4?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37178122/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com