Ruby on Rails Database Setup Tutorial
Ruby on Rails June 24th, 2008Ruby on Rails supports many different type of databases. How do you setup Ruby on Rails with your database? Here are some examples to help you out.
By default a Ruby on Rails project is generated to use SQLite for development. This database is great for development environments but not ideal for production.
Databases supported in Ruby on Rails:
- MySQL
- PostgreSQL
- SQLite (default)
- SQL Server
- IBM DB2
- Informix
- Oracle
- Firebird
MySQL
Your database.yml file will have the configuration:
development: adapter: mysql encoding: utf8 database: test_development username: root password: password host: localhost |
PostgreSQL
Install the native driver for PostgreSQL.
gem install postgres |
Your database.yml file will have the configuration:
development: adapter: postgresql database: test_development username: root password: password host: localhost |
SQLite
You will need to install the gem for SQLite support
gem install sqlite3-ruby |
Your database.yml file will have the configuration:
development: adapter: mysql encoding: utf8 database: test_development username: root password: password host: localhost |
SQL Server
You will need to install the gem for SQLite support
gem install sqlite3-ruby |
Your database.yml file will have the configuration:
development: adapter: sqlserver database: test_development username: root password: password host: localhost |
Oracle
In Rails 2.0 support for Oracle is not set by default. You will need to download the oracle adapter.
svn co http://svn.rubyonrails.org/rails/adapters/oracle/lib/active_record/connection_adapters/ |
Copy the oracle_adapter.rb file to your Ruby connection adapters directory
[your ruby path]/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/connection_adapters |
Your database.yml file will have the configuration:
# database.yml development: adapter: oracle database: [your database as it appears on TNSNAMES.ora] username: [your username] password: [your password] |
September 4th, 2008 at 5:13 am
In SQLite part, the adapter specified is ‘mysql’ instead of ’sqlite’.
October 12th, 2008 at 7:01 am
This is garbage
November 12th, 2008 at 10:07 pm
[...] your database by editing the config/database.yml file in your rails application. Refer to this quick database setup guide for the exact [...]
November 13th, 2008 at 1:54 pm
0cv7iiulzmh8jrx9