Created
June 6, 2011 15:41
-
-
Save aliang/1010487 to your computer and use it in GitHub Desktop.
Force SSL on routes, version 2, doesn't use Devise
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
YourApplication::Application.routes.draw do | |
class SSL | |
def self.matches?(request) | |
# This way you don't need SSL for your development server | |
return true unless Rails.env.production? | |
request.ssl? | |
end | |
end | |
# Reusable Proc for redirection. Will redirect with 301 (on Rails 3.0, at least) | |
ssl_for_request = Proc.new { |_, request| | |
"https://" + request.host_with_port + request.fullpath } | |
constraints SSL do | |
# Routes go here | |
match "/give_me_your_credit_card_information", :to => "pay_me#credit_card" | |
end | |
# Redirect to SSL from non-SSL so you don't get 404s | |
match "/give_me_your_credit_card_information", :to => redirect(ssl_for_request) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment