Skip to main content

TOTD #26: Overriding Database Defaults in Rails 2.0.2

Posted by arungupta on February 15, 2008 at 6:27 AM PST

A Rails 2.0.2 application configures SQLite3 database by
default. This requires you to have SQLlite3 database running and also
have the corresponding database adapter installed. Even this is part of
the Leopard (Mac OS 10.5+) development kit but this needs extra
configuration on non-Leopard machines.

One of the guiding principles of Rails is href="">Convention-over-Configuration.
So there are couple of ways you can override this default:

  1. Generate the Rails app by specifying the database of your
    choice. So if you want to use MySQL as the default database, then
    generate the application as:

    jruby -S rails -d mysql myapp

    This is assuming you are using JRuby
    for generating your Rails application.
  2. If you want to use Rails without a database, remove
    ActiveRecord framework by editing "config/environment.rb"
    and adding the line:

    config.frameworks -= [ :active_record ]

    Alternatively you can uncomment line 21 in "environment.rb"
    and remove other frameworks from inside the parentheses.

This is generally handy if you want to generate and test a simple Rails
application that does not involve database.

Please leave suggestions on other TOTD that you'd like to see. A complete
archive is available here.

Technorati: totd
jruby href="">ruby href="">leopard href="">sqlite3 href="">database

Related Topics >>