0

我的路线:

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'

路线_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

4

2 回答 2

2

把它放在 routes.rb 中:

constraints(:host => /community.website.com/) do
  match '/terms', :to => redirect {|params, request| "http://website.com/terms"}
end
于 2012-11-15T18:57:49.777 回答
0

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

terms_url(host: request.domain)

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

于 2012-11-15T18:42:59.820 回答