简体   繁体   English

Rails路由,URL和子域

[英]Rails routes, url and subdomain

We are using some subdomain in our app. 我们在应用程序中使用了一些子域。

All our dashboards have a subdomain(pro.domain.com, free.domain.com, vip.domain.com). 我们所有的仪表板都有一个子域(pro.domain.com,free.domain.com,vip.domain.com)。 In the route, each dashboard has a namespace namespace :vip do 在路由中,每个仪表板都有一个名称namespace :vip do

With rails url I'd like to be able to write <%= link_to "Be VIP", vip_pricing_path() %> and be redirected to vip.domain.com/pricing 使用rails url,我希望能够写<%= link_to "Be VIP", vip_pricing_path() %>并重定向到vip.domain.com/pricing

I don't really know how to do this. 我真的不知道该怎么做。

In routes.rb: 在routes.rb中:

Without the namespace: 没有命名空间:

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

rake routes: 耙路:

vip_pricing GET /pricing(.:format) somecontroller#someaction {:subdomain=>"vip"} vip_pricing GET /pricing(.:format)somecontroller#someaction {:subdomain =>“ vip”}

If you keep the namespace: 如果保留名称空间:

namespace :vip do
  constraints subdomain: 'vip' do
    get 'pricing', to: 'somecontroller#someaction'
    ...
  end
end

rake routes: 耙路:

vip_pricing GET /vip/pricing(.:format) vip/somecontroller#someaction {:subdomain=>"vip"} vip_pricing GET /vip/pricing(.:format)vip / somecontroller#someaction {:subdomain =>“ vip”}

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

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