Switching Ruby on Rails bases

I am starting to learn Ruby on Rails. Therefore, my application, like every Rails application, has three databases:

  • Development of
  • Test
  • Products

And the question arises: how to switch from db to another?

thanks

+2


a source to share


2 answers


By default, when you do "ruby script / server" you will be working against the development database.

Every time you run tests, doing "rake test", "rake test: functionals", etc., Rails automatically loads whatever you have in your fixtures into the test database and uses it.

Whenever you deploy to production, if you are using Phusion Passenger (which you probably should), it will by default launch your application in production mode.



If you want to run your webrick server against one of the other databases, you can do:

> ruby script/server -e production
> ruby script/server -e test

      

+3


a source


This is done by setting an environment variable RAILS_ENV

:

"RAILS_ENV" => "production"

      



Most scenarios also use a parameter -e

that lets you specify the environment. For example, when starting a web server:

ruby script/server -e production

      

+1


a source







All Articles