如何link_to子域外的路由?

时间:2012-11-15 18:39:25

标签: ruby-on-rails routes subdomain

我的路线:

class ActionDispatch::Routing::Mapper
  def draw routes_name
    instance_eval(File.read(Rails.root.join('config', 'routes', "#{routes_name}.rb")))
  end

routes_a.rb

root :to => 'home#index'
controller :home do
  post 'terms'

routes_b.rb

root :to => 'business/dashboards#show'

如果我目前位于子域community.website.com,并且我创建了一个link_to:

= link_to 'Here', terms_path

它返回community.website.com/terms而不是website.com/terms

如何退回website.com/terms

2 个答案:

答案 0 :(得分:2)

把它放在routes.rb:

constraints(:host => /community.website.com/) do
  match '/terms', :to => redirect {|params, request| "http://website.com/terms"}
end

答案 1 :(得分:0)

通常我不回答我自己的问题,但我认为这会有用:

terms_url(host: request.domain)

host: request.domain删除子域引用。