Search code examples
ruby-on-railsruby-on-rails-4routesruby-on-rails-5environment

Rails define root url based on Rails Environment


Is there any way to define different root url based on Rails environment. I want to set root :to => 'pages#index' for development and staging environment and root :to => 'beta_pages#index' for production environment.

Thanks in advance.


Solution

  • Yes, you can do that.

    In your routes.rb file:

      if Rails.env.development? || Rails.env.staging?
        root :to => 'pages#index'
      elsif Rails.env.production?
        root :to => 'beta_pages#index'
      end