views:

169

answers:

1

Is there a good way of modifying a route based on the deployment type?

Basically, I have a route that has a :requirements => {:protocol => "https"}, and I'd like that to only happen in production, but not in development.

+2  A: 

You can explicitly define them separately and test for the environment

  if Rails.env.production?
    map.resources :purchases, :requirements => {:protocol => "https"}
  else
    map.resources :purchases
  end

Note, if you're on older versions of Rails, use ENV['RAILS_ENV'] == production instead

semanticart
In general, using Rails.env.production? is the way to go. It could also be used in a before_filter that redirects to https, but this works just as well.
Thanatos
Thanks. For some reason, the fact that routes.rb is just a regular old Ruby file never hits me. This is great.
Steve Klabnik