Ruby on Rails and Oracle

  1. Get the Ruby OCI8 driver.  Download the file that ends with “mswin32.rb” and install like this:
    E:\ruby>ruby ruby-oci8-1.0.3-mswin32.rb
    Copy OCI8.rb to e:/ruby/lib/ruby/site_ruby/1.8/DBD/OCI8
    Copy oci8.rb to e:/ruby/lib/ruby/site_ruby/1.8
    Copy oci8lib.so to e:/ruby/lib/ruby/site_ruby/1.8/i386-msvcrt
    OK?
    Enter Yes/No: Yes
    Copying OCI8.rb to e:/ruby/lib/ruby/site_ruby/1.8/DBD/OCI8 ... done
    Copying oci8.rb to e:/ruby/lib/ruby/site_ruby/1.8 ... done
    Copying oci8lib.so to e:/ruby/lib/ruby/site_ruby/1.8/i386-msvcrt ... done
    OK

    You can test the driver by running a query using Ruby.

    E:\>ruby -r oci8 -e "OCI8.new('foo','12345','sid').exec(
    'SELECT * from users') do |r| puts r.join(' | ') ; end"
  2. Install the ActiveRecord Oracle adapter.gem
    E:\ruby>install activerecord-oracle-adapter --source http://gems.rubyonrails.org
  3. Update config/database.yml to connect to Oracle
    development:
      adapter: oracle
      database: sid
      username: foo
      password: 12345
      timeout: 5000
  4. Test by doing a rake db:migrate.
  5. Test by running the Ruby on Rails server and making sure there are no errors upon startup.

This article is based on these articles.

One thought on “Ruby on Rails and Oracle

  1. Pingback: betweenGo » rake db:migrate hangs

Leave a Reply

Your email address will not be published. Required fields are marked *