views:

647

answers:

2

There's several pages on the net that discuss this, but most are out of date or inaccurate in some what.

What's the scoop?

+7  A: 

Build ruby, gem, and rails

as per http://rubyonrails.org/download:

build ruby
build gem
use gem to install rails

Get Oracle Instantclient

Download from http://www.oracle.com/technology/tech/oci/instantclient/index.html

You need these two packages for your architecture.

instantclient-basic
instantclient-sdk

Unzip these files, and make this link

cd instantclient_10_2
# .dylib for mac, .so for linux
ln -s libclntsh.dylib.10.1 libclntsh.dylib

Build ruby-oci8

Download from http://ruby-oci8.rubyforge.org/en/index.html and run

# DYLD for mac
export DYLD_LIBRARY_PATH=/path/to/instantclient_10_2
# LD for linux
export LD_LIBRARY_PATH=/path/to/instantclient_10_2
ruby setup.rb config
ruby setup.rb setup
ruby setup.rb install

Test with this line and your database connection string.

ruby -r oci8 -e "OCI8.new('scott/tiger@orcl').exec('select * from user_tables') do |r| puts r.join(','); end"

Install activerecord-oracle_enhanced-adapter

Note, not activrecord-oracle-adapter as many older pages mention.

gem install activerecord-oracle_enhanced-adapter

Do that sweet rails thing

rails railstest
cd railstest
# edit config/database.yml as below
ruby script/generate scaffold comic title:string issue:integer publisher:string
rake db:migrate
ruby script/server

Test in browser

http://localhost:3000/comics

config/database.yml

Use database if you have a TNS entry, otherwise use host. Note that you have three entries (devel, test, production) to update.

development:
    adapter: oracle_enhanced
    database: orcl           # format is tns-name entry
    host:  myorclhost/orcl   # format is hostname/instance-name
    username: scott
    password: tiger

References

Mark Harrison
I keep getting a compile error when building the native part of ruby-oci8, something about wrong number of parameters. I got around this by downgrading from ruby-oci8 2.x to 1.x, this however also requires downgrading activerecord-oracle_enhanced-adapter to a version earlier than 1.2.4.In the end: `gem "activerecord-oracle_enhanced-adapter" , "1.2.3"`and `gem "ruby-oci8", "1.0.7"``works :-)
conny
+1  A: 

Some additional links to previous answer.

If you are on a Mac then you can follow tutorial How to setup Ruby and Oracle Instant Client on Mac OS X to get access to Oracle database from Ruby.

Then you can read ActiveRecord Oracle enhanced adapter wiki to get Oracle connectivity in Ruby on Rails. This adapter is used in many Ruby on Rails on Oracle projects and is under active maintenance.

I also regularly post about Ruby and Oracle at my blog.

Raimonds Simanovskis