Requiring SSL Using Route Constraints in Rails 3
The new router in Rails 3 makes it super easy to require SSL for certain routes. Just use the following in your config/routes.rb:
MyApp::Application.routes.draw do
class SslConstraint
def self.matches?(request)
request.ssl?
end
end
scope :constraints => SslConstraint do
resources :payments
# Other SSL routes go in here
end
end
Now, this is a pretty simple example–you’ll likely want to also have routes to redirect if a user tries to access without SSL, but it definitely shows off the power of the new router.

2 Comments
Abercrombie and fitch 09 Jun 2011 at 2:57AM
The Abercrombie outlet would provide you with the best casual outfits.
Glenn 03 Feb 2012 at 6:47AM
Useful information. Fortunate me I found your website accidentally, and I am stunned why this accident didn’t took place earlier! I bookmarked it.