Skip to content

Instantly share code, notes, and snippets.

@yelps
Created March 11, 2012 18:48
Show Gist options
  • Select an option

  • Save yelps/2017646 to your computer and use it in GitHub Desktop.

Select an option

Save yelps/2017646 to your computer and use it in GitHub Desktop.
Rails:force`ssl: force non ssl
class << self
def force_ssl(options = {})
host = options.delete(:host)
before_filter(options) do
if !request.ssl?
redirect_options = {:protocol => 'https://', :host => request.host, :status => :moved_permanently}
redirect_options.merge!(:host => host) if host
redirect_to "#{redirect_options[:protocol]}#{redirect_options[:host]}#{request.fullpath}", :status => redirect_options[:status]
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment