I am developing a site that mixes http and https a lot - whats the best/easiest way to make the links use the right protocol for the route - can it be specified in the route
Haven't tried but add this in your ApplicationController
:
def default_url_options(options={})
{ :secure => true }
end
For Rails 3.2 I used a combination of @apneadiving's answer. Adding the below code to my ApplicationController
def default_url_options(options={})
options.merge{ :protocol => "https" }
end
def default_url_options(options={})
{ :protocol => "https" }
end
Use test_url(:protocol => 'https')
for https urls.
You can use a plugin called ss_requirement, it will provide you with methods like ssl_required ssl_allowed
You can simply add this in your controller to enable ot disable https on any action
ssl_allowed :login, :update_profile
https://github.com/rails/ssl_requirement
Rails 3 SSL routing redirects from https to http answers this question pretty well. In short, there's not a great way to do it. I submitted the following Rails bug: https://github.com/rails/rails/issues/3571