Devin
Devin

Reputation: 911

Environment-specific routing in Rails 3

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.

Upvotes: 17

Views: 4240

Answers (1)

Casual Coder
Casual Coder

Reputation: 1492

routes.rb is Ruby file so this should work:

  if Rails.env.production?
    get "/bar" => 'welcome#index'
  else
    get "/foo" => 'welcome#index'
  end

Upvotes: 25

Related Questions