可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I'm trying to run the rails (4.1.2
) console
rails c RAILS_ENV=test
And I'm getting this:
> config.eager_load is set to nil. Please update your > config/environments/*.rb files accordingly: > > * development - set it to false * test - set it to false (unless > you use a tool that preloads your test environment) * production - > set it to true > > /Users/xxxxxx/.rvm/gems/ruby-2.2.2/gems/activerecord-4.1.12/lib/active_record/connection_adapters/connection_specification.rb:257:in > `resolve_symbol_connection': 'RAILS_ENV=test' database is not > configured. Available: ["development", "test", "production"] > (ActiveRecord::AdapterNotSpecified)
Yet in my test.rb
I have config.eager_load = false
and my database.yml
is ok (I ran rake db:schema:load RAILS_ENV=test
without issues.
How can I solve this?
回答1:
You need to declare the env before you run the commands:
RAILS_ENV=test bundle exec rails c
I get the same output on my computer:
> bundle exec rails c RAILS_ENV=test ian@Ians-MacBook-Pro config.eager_load is set to nil. Please update your config/environments/*.rb files accordingly: * development - set it to false * test - set it to false (unless you use a tool that preloads your test environment) * production - set it to true
but when I run as suggested:
> RAILS_ENV=test bundle exec rails c ian@Ians-MacBook-Pro Loading test environment (Rails 4.2.3)
回答2:
As for Windows systems:
This should do:
rails c -e test
Or set the RAILS_ENV
variable first:
set RAILS_ENV=test rails c
回答3:
On Windows there is a glitch with RAILS_ENV
. If you run
SET RAILS_ENV=development<SPACE> <- with a space symbol after word "development"
then you will get the error:
config.eager_load is set to nil. Please update your config/environments/*.rb fil es accordingly:
when doing rails server webrick
.
So make sure you do type without a trailing space (and no quotes)
SET RAILS_ENV=development<ENTER>
The same applies to all environments: test, production and development.
回答4:
Make sure you have your
production.rb
development.rb
test.rb
files in config/environments/ folder.