I'm currently trying to find out a way to force http for some routes (faster, no need for security) and forcing https for more sensitive pages. I saw the answer to this: Rails 3 SSL Deprecation , but it doesn't seem to work.
I added a scope around my root url:
scope :constraints => { :protocol => 'http' } do
root :to => 'site#index'
end
But it just threw the error No route matches [GET] "/"
when I tried to go to localhost:3000.
Is there a clean way to force http in some places and force https in others (I could use force_ssl
in my controller, but is there a force_http
?) The scope around the routes looks clean, but it isn't working for me. Am I doing it wrong?
How about a method like this?
CONTROLLERS_THAT_REQUIRE_SSL = ['check_out']
def ensure_proper_protocol
unless Rails.env.development? || Rails.env.test?
if request.protocol["https"] && !CONTROLLERS_THAT_REQUIRE_SSL.include?(params[:controller])
redirect_to "http://" + request.host + request.path
end
end
end