2012-11-15 43 views
0

我的路線:如何link_to子域外的路由?

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而不是。如何返回?

回答

0

通常我不回答我自己的問題,但我認爲這將是有益的:

terms_url(host: request.domain) 

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

2

在routes.rb中加上:

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

啊好主意! – Trip