Ruby on rails Rails路由、url和子域

Ruby on rails Rails路由、url和子域,ruby-on-rails,routing,routes,subdomain,Ruby On Rails,Routing,Routes,Subdomain,我们正在应用程序中使用一些子域 我们所有的仪表盘都有一个子域(pro.domain.com、free.domain.com、vip.domain.com)。 在路由中,每个仪表板都有一个名称空间名称空间:vip do 通过rails url,我希望能够编写,并被重定向到vip.domain.com/pricing 我真的不知道怎么做。在routes.rb中: 没有名称空间: constraints subdomain: 'vip' do get '/pricing', to: 'someco

我们正在应用程序中使用一些子域

我们所有的仪表盘都有一个子域(pro.domain.com、free.domain.com、vip.domain.com)。 在路由中,每个仪表板都有一个名称空间
名称空间:vip do

通过rails url,我希望能够编写
,并被重定向到vip.domain.com/pricing

我真的不知道怎么做。

在routes.rb中:

没有名称空间:

constraints subdomain: 'vip' do
  get '/pricing', to: 'somecontroller#someaction', :as=>:vip_pricing
end
namespace :vip do
  constraints subdomain: 'vip' do
    get 'pricing', to: 'somecontroller#someaction'
    ...
  end
end
耙道:

vip定价获取/定价(:格式)somecontroller#someaction {:子域=>“vip”}

如果保留名称空间:

constraints subdomain: 'vip' do
  get '/pricing', to: 'somecontroller#someaction', :as=>:vip_pricing
end
namespace :vip do
  constraints subdomain: 'vip' do
    get 'pricing', to: 'somecontroller#someaction'
    ...
  end
end
耙道:

vip#u pricing GET/vip/pricing(:format)vip/somecontroller#someaction{:子域=>“vip”}


但据我所知,只有当我浏览这个子域时,约束才会使路由可用。正确吗?对于命名空间之外的示例:如果此路由“/pricing”在子域“vip”中命中,它将路由到您指定的控制器/操作。这就是你想要的,对吗?此外,当您使用帮助程序“vip\U定价\U url”时,您将在询问问题时获得子域。