How can I start the rails console and use the testing database exclusively?
in Rails 6 the syntax has changed for this
rails c -e test
You can pass the environment as 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 >
To start console in test
environment:
ruby script/console test
ruby script/console production
To run rake tasks in test
environment:
rake db:create RAILS_ENV=test
rake db:migrate RAILS_ENV=test
In Rails 3 and 4 you can use:
rails console test
rails c test
In Rails 5 you can use:
rails console -e test
rails c -e test