I have a ssl certificate which serves https://secure.mydomain.com. I would like to use ssl only on certain controllers and not throughout my entire application. I have looked online and can't seem to find a complete and accurate tutorial on how to enable ssl for specified controllers.
I am aware that I can use the config ssl below but it does not serve me a purpose since it enables ssl site wide
config.force_ssl = true
How can I tell rails to only use ssl on a specific controller rather then my entire application?
You can do this with constraints in routes.rb:
resource :account, :constraints => { :protocol => "https", :subdomain => "secure" }
Also, if you have many secure routes, and you want to DRY things up, you can create a scope
for your secure routes:
scope :constraints => { :protocol => "https", :subdomain => "secure" } do
...[secure routes]...
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With