Rails redirect_to丢失了https协议,并转至http

Joe*_*lsh 5 ssl ruby-on-rails

redirect_to example_path在控制器中使用时,协议会更改为http。我希望协议保持与原始请求相同,例如,如果我使用https,我想重定向到https:// example_path ...,如果我使用http,我想重定向到http:// example_path ...

我知道我可以使用,config.force_ssl = true但我希望ssl是可选的。

rub*_*bie 2

redirect_to 在其 args 哈希中采用协议密钥。你可以做

redirect_to example_path, protocol: request.protocol
Run Code Online (Sandbox Code Playgroud)

这应该能让你排序。如果这不起作用,请告诉我。