开发者

Switching Ruby on Rails databases

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

  • Development
  • Test
  • Production

And the question is: ho开发者_开发知识库w do i switch from a db to another?

Thanks


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


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜