Hi, this blog is no longer maintained, my new blog is here

Ruby On Rails and a Conning Israeli entrepreneur

Ruby on Rails and Oracle on Mac Os Leopard

Overview


The nightmare is over.
Just until the latest Oracle libraries update (finally released a X86 library pack for mac) it was nesecerry to use 2 versions of ruby, a universal and a ppc version. Sadly, when running PPC, the benchmarking were terrible and it had some very annoying freezes and other stuff that would simple make you want to jump off the roof.
BUT! (:) ) times had changed, Oracle (as mentioned) released an X86 Intel compatible library pack for MacOs users and therefore ended my misery,
Woohoo! That makes the entire process of connection Ruby on Rails and oracle on Leopard about as 100 times less complicated than before, so I’ve posted it here to let everyone enjoy.
I assumes that you’re using Rails 2.0 or greater (Why not really?).

IMPORTART!!!

If you already connected Oracle and Ruby on Rails using the old way, please preform the "Cleanup" step first.


Oracle Libraries


The new Intel Mac versions are available from the Oracle downloads site. Install them in /Library/Oracle/.
You can do side-by-side installations in folders with whatever names you want, since apps find them by using the $ORACLE_HOME environment variable (and it’s friends). I’ve got mine in /Library/Oracle/instantclient_10_2.
Also make sure that you’ve got the files required to run sqlplus and the sdk along with the basic. You can drop those in the same directory.

Symlink the libraries



In the directory where you’ve installed the instant client, run this:


ln -s libclntsh.dylib.10.1 libclntsh.dylib


Set the environment variables correctly

You’ll probably want to put these lines in your /etc/profile , but they also must be run from the command line to take effect (you can also "source /etc/profile"):


export ORACLE_HOME=/Library/Oracle/instantclient_10_2 <= Change to your library!
export TNS_ADMIN=$ORACLE_HOME
export LD_LIBRARY_PATH=$ORACLE_HOME
export DYLD_LIBRARY_PATH=$ORACLE_HOME
export PATH=$PATH:$ORACLE_HOME



Oracle! giddie up!



First you'll need to install the Active Record Oracle adapter,


sudo gem install activerecord-oracle-adapter --source http://gems.rubyonrails.org


which is how ActiveRecord deals with Oracle.
It doesn’t, however, install the Ruby oci8 driver, which is how Ruby talks to Oracle (yeah, annoying).

Important!!!

Have you installed the Oracle Instant Client SDK ?
good.


Get the lastest the oci8 library. Download it and unpack the file in the finder: it should unzip into ~/Downloads/ruby-oci8-x.x.x.

Now we can finish configuring the environment before we compile the library.


cd ~/Downloads/ruby-oci8-x.x.x
export SQLPATH=$ORACLE_HOME
export RC_ARCHS=i386
ruby setup.rb config
make
sudo make install


oh joy, scrolling lines of doom will pass in front of you and hopefully you'll see no errors and burst into tears.

Show me!



At this point, we’re almost done. Let's see it working.


irb
require 'oci8'
==> true

or

irb
require 'rubygems'
==> []
require 'oci8'
==> true



Configure your database.yml


In your database.yml, use the following to make it work:

development:
adapter: oracle
database: your_instance_name
username: your_user_name
password: your_password


The database name = > comes straight out of your tnsnames.ora file. You don’t need to specify any other connection information in database.yml, since the tnsnames.ora file has everything you need.

if you are using the oracle Express edition, it should look something like that.

development:
adapter: oci
host: //db_hostname:db_port/xe <== Oracle port is usually 1521
username: username
password: password
cursor_sharing: similar
prefetch_rows: 100


note: last 2 lines are some tweaking for a better Oracle performance.



Cleanup: Fix the ruby_fat and ruby_ppc setup



if you have installed Oracle libraries using the old way, you'll be happy to remove the mess it made out of your ruby installation and happily, it’s quite simple.
Just remove the ruby_ppc files, and the symlinks to them (called ruby, and rename ruby_fat as ruby:


cd /usr/bin <== or wherever you put them.
sudo rm ruby
sudo rm ruby_ppc
sudo mv ruby_fat ruby

and

cd /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin
sudo rm ruby
sudo rm ruby_ppc
sudo mv ruby_fat ruby


Then, you should also remove the 2 management scripts:


sudo rm /usr/bin/ppc_ruby.sh
sudo rm /usr/bin/fat_ruby.sh


And that’s enough for the cleanup.

1 comments:

  Anonymous

February 26, 2009 at 2:43 AM

Any insight into a good full-text search solution for Rails and Oracle? None of the popular full-text searching plug-ins for Rails seem to support Oracle, are there any alternatives?


The Web Ask eizesus.com

Subscribe

    follow me on Twitter

    Twiters Around

    About Me

    My photo
    I am a web developer for more than 9 years, managed, cried, coded, designed and made money in this industry. now trying to do it again.

    Labels