views:

30

answers:

2

Hi,

I'm starting learning Ruby on Rails. So my application, like every Rails app, has three databases:

  • Development
  • Test
  • Production

And the question is: how do i switch from a db to another?

Thanks

+1  A: 

It's done by setting the RAILS_ENV environment variable:

"RAILS_ENV" => "production"

Most of the scripts also take a -e parameter which allows you to specify the environment. For example when you start the web server:

ruby script/server -e production
Darin Dimitrov
Why has this been down-voted? Please leave a comment when down-voting.
Darin Dimitrov
+1  A: 

By default whenever you do "ruby script/server" you are going to be running against the development database.

Any time you run tests, by doing "rake test", "rake test:functionals", etc, Rails will automatically load up anything you have in your fixtures into the test database and use that.

Whenever you deploy into production, if you use Phusion Passenger (which you probably should), it will by default run your app in production mode.

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

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