I'm trying to run the rails (4.1.2
) console
我正在尝试运行rails(4.1.2)控制台
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.
然而在我的test.rb中我有config.eager_load = false并且我的database.yml没问题(我运行了rake db:schema:加载RAILS_ENV = test没有问题。
How can I solve this?
我怎么解决这个问题?
3 个解决方案
#1
26
You need to declare the env before you run the commands:
您需要在运行命令之前声明env:
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
1
As for Windows systems:
至于Windows系统:
-
This should do:
这应该做:
rails c -e test
-
Or set the
RAILS_ENV
variable first:或者首先设置RAILS_ENV变量:
set RAILS_ENV=test rails c
#3
0
On Windows there is a glitch with RAILS_ENV
. If you run
在Windows上,RAILS_ENV出现故障。如果你跑
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:
config.eager_load设置为nil。请相应地更新您的config / environments / * .rb文件:
when doing rails server webrick
.
当做rails服务器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.
这同样适用于所有环境:测试,生产和开发。
#1
26
You need to declare the env before you run the commands:
您需要在运行命令之前声明env:
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
1
As for Windows systems:
至于Windows系统:
-
This should do:
这应该做:
rails c -e test
-
Or set the
RAILS_ENV
variable first:或者首先设置RAILS_ENV变量:
set RAILS_ENV=test rails c
#3
0
On Windows there is a glitch with RAILS_ENV
. If you run
在Windows上,RAILS_ENV出现故障。如果你跑
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:
config.eager_load设置为nil。请相应地更新您的config / environments / * .rb文件:
when doing rails server webrick
.
当做rails服务器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.
这同样适用于所有环境:测试,生产和开发。