I'd like to create a scope in my routes.rb file to only route certain URLs when in the production environment. How do you use conditionals with Rails 3 routing? All I need to do is restrict those rules based on Rails.env.production?
being true, but I'm not sure of the syntax.
Decoding the http request 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.
Rails RESTful Design which creates seven routes all mapping to the user controller. Rails also allows you to define multiple resources in one line.
Difference between singular resource and resources in Rails routes. So far, we have been using resources to declare a resource. Rails also lets us declare a singular version of it using resource. Rails recommends us to use singular resource when we do not have an identifier.
routes.rb
is Ruby file so this should work:
if Rails.env.production?
get "/bar" => 'welcome#index'
else
get "/foo" => 'welcome#index'
end
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