Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails redirect_to loses the https protocol and goes to http

When using redirect_to example_path in the controller the protocol gets changed to http. I want the protocol to remain the same as the original request e.g. if I'm using https I want to be redirected to https://example_path... and if I'm using http I want to be redirected to http://example_path...

I know I can use config.force_ssl = true but I want ssl to be optional.

like image 608
Joe Walsh Avatar asked Jun 23 '16 14:06

Joe Walsh


1 Answers

redirect_to takes a protocol key in its args hash. You can do

redirect_to example_path, protocol: request.protocol

and that should get you sorted. Let me know if that doesn't work.

like image 154
ruby_newbie Avatar answered Sep 21 '22 13:09

ruby_newbie