Created
March 11, 2012 18:48
-
-
Save yelps/2017646 to your computer and use it in GitHub Desktop.
Rails:force`ssl: force non ssl
This file contains hidden or 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
| 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