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.
Go to your browser and open http://localhost:3000, you will see a basic Rails app running. You can also use the alias "s" to start the server: bin/rails s . The server can be run on a different port using the -p option. The default development environment can be changed using -e .
You can use rails dbconsole to view the database that your rails application is using. It's alternative answer rails db . Both commands will direct you the command line interface and will allow you to use that database query syntax.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With