Skip to content

Instantly share code, notes, and snippets.

@dabit
Created September 26, 2012 04:05
Show Gist options
  • Save dabit/3785941 to your computer and use it in GitHub Desktop.
Save dabit/3785941 to your computer and use it in GitHub Desktop.
force_ssl comparison
#
# 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