首先,这看起来更像是一个错误,然后是其他任何东西。Rails应用程序在代理之后,使用SSL,将路径呈现为“http://”
我的导轨应用程序由Unicorn提供。然后,使用Nginx作为反向代理,我使用SSL将应用程序提供给外部世界。
到目前为止好,没问题。我使用相对路径(宁静路径佣工),所以应该没有问题,产生这样(为https://www.example.com):
new_entry_path => https://www.example.com/entries/new
这在大多数情况下的罚款。
当控制器我尝试重定向到一个“秀”操作(使用资源),让成功更新后说,这个问题却出现(假设输入ID为100):
redirect_to @entry, flash: {success: "Entry has been updated"}
或
redirect_to entry_path(@entry), flash: {success: "Entry has been updated"}
他们都产生一个重定向到:
http://www.example.com/entries/100 # missing 's' in https...
在的
/entries/100 # implying https://www.example.com/entries/100
代替据我已经注意到,这仅与show
行动,只有在控制器重定向发生。
redirect_to entry_url(@entry).sub(/^http\:/,"https:"), flash: {success: "Entry has been updated"}
有没有人遇到类似的事情:
我做什么可怕的,恶心的绕过这个?任何想法将欣然接受......
有你尝试设置默认主机? http://stackoverflow.com/questions/2660172/how-do-i-set-default-host-for-url-helpers-in-rails – max 2014-09-26 21:48:12
我见过,但我试图让object_path helpers工作,而不是object_url帮手......这会帮助我吗? – 2014-09-26 21:50:09
我相信如此,因为'redirect_to'使用''url_for' [引擎盖下](https://github.com/rails/rails/blob/3e006d5076a393c827fba69bf72bc36b7abf921b/actionpack/lib/action_controller/metal/redirecting.rb#L65) – max 2014-09-26 21:58:57