Created
September 26, 2012 04:05
-
-
Save dabit/3785941 to your computer and use it in GitHub Desktop.
force_ssl comparison
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Rails 3.1 | |
# | |
def force_ssl(options = {}) | |
before_filter(options) do | |
if !request.ssl? && !Rails.env.development? | |
redirect_to :protocol => 'https://', :status => :moved_permanently | |
end | |
end | |
end | |
# | |
# Rails 3.2 | |
# | |
def force_ssl(options = {}) | |
host = options.delete(:host) | |
before_filter(options) do | |
if !request.ssl? && !Rails.env.development? | |
redirect_options = {:protocol => 'https://', :status => :moved_permanently} | |
redirect_options.merge!(:host => host) if host | |
redirect_options.merge!(:params => request.query_parameters) | |
redirect_to redirect_options | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment