尝试在测试中运行Rails C时将config.eager_load设置为nil [英] Getting config.eager_load is set to nil while trying to run rails c in test

查看:205
本文介绍了尝试在测试中运行Rails C时将config.eager_load设置为nil的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试运行rails(4.1.2)控制台

I'm trying to run the rails (4.1.2) console

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没问题.

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.

我该如何解决?

推荐答案

在运行命令之前,您需要声明env:

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)

这篇关于尝试在测试中运行Rails C时将config.eager_load设置为nil的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆