Reputation: 19979
I have config.force_ssl = true
in my production.rb for a Ruby on Rails 5 app but need to have a single controller NOT force_ssl. Is this possible without configuring each controller? Is there a way to unforce_ssl
within a single controller?
Upvotes: 1
Views: 29
Reputation: 6952
You could create a secure controller:
class SecureController < ApplicationController
force_ssl
end
Then you can make all controllers inherit SecureController
class ThingsController < SecureController
...
end
Except for the one in question. You'll have to make a one-time change to all controllers that you want this to apply to, but the good news is that you'll only have to do it once, and you then have the ability to extend functionality to SecureController. Sounds like your question is asking for a way to :skip
, or :except
on a before_action
, but most Rails developers I know agree that this is the way it should be done.
Upvotes: 2
Reputation: 1077
according to this page
You can pass any of the following options to affect the before_action callback
only - The callback should be run only for this action
except - The callback should be run for all actions except this action
if - A symbol naming an instance method or a proc; the callback will be called only when it returns a true value.
unless - A symbol naming an instance method or a proc; the callback will be called only when it returns a false value.
This is using the controller level force_ssl though.
The config level force_ssl, is application wide
Upvotes: 0