ruby-on-rails - 尝试在测试中运行 rails c 时获取 config.eager_load 设置为 nil

标签 ruby-on-rails ruby config environment

我正在尝试运行 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 没有问题。

我该如何解决这个问题?

最佳答案

您需要在运行命令之前声明环境:

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)

关于ruby-on-rails - 尝试在测试中运行 rails c 时获取 config.eager_load 设置为 nil,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31999625/

相关文章:

php - 在 PHP 和 Zend Framework 中使用 cofigs.ini 的优点?

ruby-on-rails - 有没有办法在模块中使用类方法而不在 Rails 中扩展它?

ruby-on-rails - rails 3 : Create seed data from development database

javascript - 如何将 javascript 变量设置为 Rails 模型中的列表?

ruby-on-rails - Rails 3 操作邮件程序制作 OpenSSL::SSL::SSLError: 主机名与服务器证书不匹配

ruby - Ubuntu 中的命令正在安装 ruby​​ 1.8,而不是最新的 1.9

ruby-on-rails - Rails如何处理并发请求

ruby - 如何告诉 bundler Gemfile 在哪里?

python - 难以更新按钮回调内的标签

.net - 设置文件与 app.config