尝试在测试中运行rails c时,将config.eager_load设置为nil
我正在尝试运行rails( 4.1.2
)控制台
rails c RAILS_ENV=test
我得到了这个:
> 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)
然而在我的test.rb
我有config.eager_load = false
并且我的database.yml
没问题(我运行了rake db:schema:load RAILS_ENV=test
没有问题。
我怎么解决这个问题?
您需要在运行命令之前声明env:
RAILS_ENV=test bundle exec rails c
我在计算机上得到相同的输出:
> 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
但是当我按照建议跑步时:
> RAILS_ENV=test bundle exec rails c ian@Ians-MacBook-Pro Loading test environment (Rails 4.2.3)
至于Windows系统:
-
这应该做:
rails c -e test
-
或者首先设置
RAILS_ENV
变量:set RAILS_ENV=test rails c
在Windows上, RAILS_ENV
出现故障。 如果你跑
SET RAILS_ENV=development <- with a space symbol after word "development"
然后你会得到错误:
config.eager_load is set to nil. Please update your config/environments/*.rb fil es accordingly:
当做rails server webrick
。
因此,请确保您键入时没有尾随空格(并且没有引号)
SET RAILS_ENV=development
这同样适用于所有环境:测试,生产和开发。
确保你有
-
production.rb
-
development.rb
-
test.rb
config / environments /文件夹中的文件。