Set your Rails Environment Globally
June 20th, 2009
In much of the rails documentation it is suggested that when you want to run a task in a specific environment, you should set the RAILS_ENV environment variable on the command line where you are running the task.
For example, assume you want to run rake db:migrate on the production system (should be done automatically by Capistrano, but anyway..), because it is the production system, you would have to declare your rails environment in the command line, so you would actually have to run RAILS_ENV=production rake db:migrate.
Well, this becomes tedious sometimes, and open to human error as well. Luckily there is a way around this.
The solution is simple.
Add it to your /etc/environment file:
RAILS_ENV=production
You may have to log out and log in again of your shell for it to take effect. Put this on your production server, and any command that runs on that production server will automatically default to the production environment. This includes cron jobs, and other users logging into the same system.
Handy!
Categories: Rails
Most People subscribe via RSS Feed
Add to del.icio.us
Stumble It