Getting config.eager_load is set to nil while trying to run rails c in test

非 Y 不嫁゛ 提交于 2019-12-08 14:29:57

问题


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:

  1. This should do:

    rails c -e test
    
  2. 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.




回答5:


Needs to set

config.eager_load = false

for config/environments/development.rb and test.rb or = true for production.rb (as default)



来源:https://stackoverflow.com/questions/31999625/getting-config-eager-load-is-set-to-nil-while-trying-to-run-rails-c-in-test

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!