2016-05-11 78 views
1

我正在處理處理多個域的流量的Rails應用程序。我以用我的路線約束來實現這一點:直到我嘗試做從bar.com一個redirect_to @user在rails中處理多個域

constraints domain: 'foo.com' do 
... 
end 

constraints domain: 'bar.com' do 
... 
end 

,一切工作正常。它最終通過foo.com路由重定向,因爲那個在我的routes.rb文件中首先出現。

我該如何解決這個問題?

回答

1

不確定這是100%的「方式」,因爲我不確定您可能會遇到什麼業務限制,但看起來像這樣的東西可能會起作用(也許會起到一個很好的起點作用):

# in your controller method 
def w00t 
    # the_current_host in my example is "dynamic" but could be static 
    # should that better fit your needs, of course 
    the_current_host = request.protocol + request.host 
    redirect_to user_url(@user, host: the_current_host) 
end 

請注意,我只是「隨機」挑選request.protocolrequest.host ...你可以探索request object和決定是正確的爲您服務。

+0

謝謝。這確實有效。任何想法爲什麼重定向本身沒有捕捉? – connor

+0

非常好!我並不完全確定,但我的感覺是,根據您的陳述要求,明確主持人將確保其始終按預期工作。對不起,我現在沒有比這更好的解釋! –