I'd like to start the rails console and create database entries in a database that isn't the default database, such as the testing database. I'd appreciate any help.
我想启动rails控制台并在不是默认数据库的数据库中创建数据库条目,例如测试数据库。我很感激任何帮助。
3 个解决方案
#1
46
To start console in test
environment:
要在测试环境中启动控制台:
ruby script/console test
ruby script/console production
To run rake tasks in test
environment:
要在测试环境中运行rake任务:
rake db:create RAILS_ENV=test
rake db:migrate RAILS_ENV=test
In Rails 3 or above you can use:
在Rails 3或更高版本中,您可以使用:
rails console test
rails c test
#2
6
You can pass the environment as RAILS_ENV=test
:
您可以将环境作为RAILS_ENV = test传递:
$ RAILS_ENV=test bundle exec rails console
Or:
要么:
$ RAILS_ENV=test bundle exec rails c
You can also do:
你也可以这样做:
$ bundle exec rails console test
Or:
要么:
$ bundle exec rails c test
You can see like
你可以看到像
Loading test environment (Rails 3.2.8)
1.9.3p327 :001 >
#3
0
$ RAILS_ENV=test ./script/console
#1
46
To start console in test
environment:
要在测试环境中启动控制台:
ruby script/console test
ruby script/console production
To run rake tasks in test
environment:
要在测试环境中运行rake任务:
rake db:create RAILS_ENV=test
rake db:migrate RAILS_ENV=test
In Rails 3 or above you can use:
在Rails 3或更高版本中,您可以使用:
rails console test
rails c test
#2
6
You can pass the environment as RAILS_ENV=test
:
您可以将环境作为RAILS_ENV = test传递:
$ RAILS_ENV=test bundle exec rails console
Or:
要么:
$ RAILS_ENV=test bundle exec rails c
You can also do:
你也可以这样做:
$ bundle exec rails console test
Or:
要么:
$ bundle exec rails c test
You can see like
你可以看到像
Loading test environment (Rails 3.2.8)
1.9.3p327 :001 >
#3
0
$ RAILS_ENV=test ./script/console