Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 在rails中处理多个域_Ruby On Rails_Ruby On Rails 4 - Fatal编程技术网

Ruby on rails 在rails中处理多个域

Ruby on rails 在rails中处理多个域,ruby-on-rails,ruby-on-rails-4,Ruby On Rails,Ruby On Rails 4,我正在使用Rails应用程序处理多个域的流量。我通过在路线中使用约束实现了这一点,使用: constraints domain: 'foo.com' do ... end constraints domain: 'bar.com' do ... end 一切正常,直到我尝试从bar.com将重定向到@user。它最终通过route foo.com重定向,因为它首先出现在我的routes.rb文件中 我如何解决这个问题?不确定这是100%的“方法”,因为我不确定您是否受到任何业务限制,但这样做

我正在使用Rails应用程序处理多个域的流量。我通过在路线中使用约束实现了这一点,使用:

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

constraints domain: 'bar.com' do
...
end
一切正常,直到我尝试从bar.com将
重定向到@user
。它最终通过route foo.com重定向,因为它首先出现在我的routes.rb文件中

我如何解决这个问题?

不确定这是100%的“方法”,因为我不确定您是否受到任何业务限制,但这样做似乎是可行的(并且可能有助于作为一个良好的起点):


注意,我只是“随机”选择了
request.protocol
request.host
。。。你可以探索这些方法,并为自己选择合适的方法

多谢各位。这确实奏效了。知道为什么重定向本身没有被捕获吗?太好了!我不完全确定,但我的感觉是,考虑到你所说的要求,对主持人的明确描述将确保它始终按预期工作。对不起,我现在没有比这更好的解释了!
# 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