问题
I have a problem where
rails console test
results in
Loading development environment (Rails 3.1.0)
I suspect it's a RAILS_ENV
problem because doing
RAILS_ENV=test rails console
results in
Loading test environment (Rails 3.1.0)
Any suggestions? Thanks.
回答1:
Yes, you must specify RAILS_ENV
or use rails console [environment]
.
回答2:
Is environment variable RAILS_ENV already set (in your command line environment)?
Ideally, rails console test
should set RAILS_ENV to 'test' and disregard its value in the command line environment.
However, if it is set to something (nonblank) other than 'test', then, obviously, potentially one might see a difference in behavior between rails console test
and RAILS_ENV=test rails console
.
EDIT: If RAILS_ENV is set to development in my shell environment, and I do rails console test
, then I get the test environment, just as Adam Eberlin and Brian also report.
It's still mysterious (to me) what might be different in your setup, or what's causing your observed difference in behavior.
Therefore, you should not accept this (my) answer!
来源:https://stackoverflow.com/questions/7668167/rails-console-test-loading-development-environment