我有一个共享对话框。如何使用rails输出当前协议和url?
在开发它看起来像:
http://xxxxxx.com/stuff
PROD上:
https://yyyyyyyyyyy.com/stuff
什么是最好的轨的方式输出#协议## URL#
在哪里我可以在轨道中设置这些吗?谢谢
我有一个共享对话框。如何使用rails输出当前协议和url?
在开发它看起来像:
http://xxxxxx.com/stuff
PROD上:
https://yyyyyyyyyyy.com/stuff
什么是最好的轨的方式输出#协议## URL#
在哪里我可以在轨道中设置这些吗?谢谢
request.protocol
request.url
要求对象。您可以使用request.fullpath
API参考是here
最好的办法,我发现:
url_for(:only_path => false)
尝试添加以下到您development.rb文件
Rails.application.routes.default_url_options[:protocol] = 'http'
和production.rb文件
Rails.application.routes.default_url_options[:protocol] = 'https'
'request.fullpath'在这种情况下会返回'/ stuff'。 – bhaity