Search code examples
ruby-on-rails-4productionstaging

How to automatically set RAILS_ENV based on server


While in development we don't need to set RAILS_ENV when we run rails c and it automatically load development environment. However, when I am on staging server I would like to ignore passing RAILS_ENV when we run rails c; it should automatically load staging environment rather than development. Unfortunately, we always face loading development environment. So we would like to know how to do this automatically to load dynamic environment when on staging or production server.


Solution

  • You could probably set an environment variable in your ~/.bashrc file like so:

    export RAILS_ENV=staging