我正在尝试运行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
没有问题。
我该如何解决这个问题?
答案 0 :(得分:28)
您需要在运行命令之前声明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)
答案 1 :(得分:2)
至于Windows系统:
这应该做:
rails c -e test
或先设置RAILS_ENV
变量:
set RAILS_ENV=test
rails c
答案 2 :(得分:0)
在Windows上,RAILS_ENV
出现故障。如果你运行
SET RAILS_ENV=development<SPACE> <- 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<ENTER>
这同样适用于所有环境:测试,生产和开发。
答案 3 :(得分:0)
确保您拥有
production.rb
development.rb
test.rb
config / environments /文件夹中的文件。
答案 4 :(得分:0)
需要设置
config.eager_load = false
对于config / environments / development.rb和test.rb或= true
对于production.rb(默认)
答案 5 :(得分:0)
这很愚蠢,但是我在运行rails c
而不是rails g
时遇到了这个问题。这是有道理的,因为我传递给generate命令的内容对于控制台命令无效。