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.
Rails routes are matched in the order they are specified, so if you have a resources :photos above a get 'photos/poll' the show action's route for the resources line will be matched before the get line. To fix this, move the get line above the resources line so that it is matched first.
Rails RESTful Design which creates seven routes all mapping to the user controller. Rails also allows you to define multiple resources in one line.
TIP: If you ever want to list all the routes of your application you can use rails routes on your terminal and if you want to list routes of a specific resource, you can use rails routes | grep hotel . This will list all the routes of Hotel.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With