Module: ActionController::ForceSSL::ClassMethods
- Defined in:
- lib/action_controller/metal/force_ssl.rb
Instance Method Summary collapse
-
#force_ssl(options = {}) ⇒ Object
Force the request to this particular controller or specified actions to be under HTTPS protocol.
Instance Method Details
#force_ssl(options = {}) ⇒ Object
Force the request to this particular controller or specified actions to be under HTTPS protocol.
If you need to disable this for any reason (e.g. development) then you can use an :if
or :unless
condition.
class AccountsController < ApplicationController
force_ssl if: :ssl_configured?
def ssl_configured?
!Rails.env.development?
end
end
URL Options
You can pass any of the following options to affect the redirect url
-
host
- Redirect to a different host name -
subdomain
- Redirect to a different subdomain -
domain
- Redirect to a different domain -
port
- Redirect to a non-standard port -
path
- Redirect to a different path
Redirect Options
You can pass any of the following options to affect the redirect status and response
-
status
- Redirect with a custom status (default is 301 Moved Permanently) -
flash
- Set a flash message when redirecting -
alert
- Set a alert message when redirecting -
notice
- Set a notice message when redirecting
Action Options
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 callbackwill be called only when it returns a true value.
-
unless
- A symbol naming an instance method or a proc; the callbackwill be called only when it returns a false value.
62 63 64 65 66 67 68 |
# File 'lib/action_controller/metal/force_ssl.rb', line 62 def force_ssl( = {}) = .slice(*ACTION_OPTIONS) = .except(*ACTION_OPTIONS) before_action() do force_ssl_redirect() end end |