What's the proper way to enforce https in a rails 4 route?
For example I would expect to be able to do something like:
get 'success' => 'ssl#success', :ssl_only => true
But that doesn't do anything.
What's the proper way to enforce https in a rails 4 route?
For example I would expect to be able to do something like:
get 'success' => 'ssl#success', :ssl_only => true
But that doesn't do anything.
You can use force_ssl
to force http://site/success
to redirect to https://site/success
. Please refer to the documentation for force_ssl.
class SSLController < ApplicationController
force_ssl only: :success # see docs for more options
end
If you want https://.../ssl/success
scope constraints: { protocol: 'https' } do
get 'success', to: 'ssl#success', as: 'success'
end
or
get 'success', to: 'ssl#success', as: 'success', constraints: { protocol: 'https' }
I eventually got this to work with:
get 'success', to: 'ssl#success', constraints: {protocol: /https/}
In my case it worked by adding "force_ssl" in the application_controller.rb.