Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I start the rails console and use the testing database exclusively?

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.

like image 226
James Avatar asked Mar 05 '10 23:03

James


People also ask

How do I start rails console?

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 .

How do I view a Rails database?

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.


Video Answer


1 Answers

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 
like image 53
Harish Shetty Avatar answered Sep 22 '22 20:09

Harish Shetty