Rails console default environment

user82216 picture user82216 · May 29, 2012 · Viewed 13.4k times · Source

On my development machine:

$ bundle exec rails console
Loading development environment (Rails 3.2.3)
1.9.3p194 :001 > Rails.env
 => "development"

This is expected. So far, so good.

Yet on my production server (to which I have deployed using Capistrano), I get exactly the same result:

$ bundle exec rails console
Loading development environment (Rails 3.2.3)
1.9.3p194 :001 > Rails.env
 => "development"

On either machine, I can instead do:

$ bundle exec rails console production
Loading development environment (Rails 3.2.3)
1.9.3p194 :001 > Rails.env
 => "production"

My question is: on the production server, shouldn't bundle exec rails console load the production environment by default, instead of the development environment? And if not, why not?

Answer

jigfox picture jigfox · May 29, 2012

The rails executable can't know which environment should run on which machine.

you can put export RAILS_ENV=production in your ~/.bashrc or ~/.bash_profile file of the user you want to start the console with.