On 10/16/07, Matthew W. [email protected] wrote:
But is this the right method for me?
When a user uses my application it determines who they are via their
Windows Login. Using that login I have the capability to query an
Oracle database and retrieve all the information on that user. So when
the user logs into my application I would like to make the call to that
Oracle database, pull down their information and continue with the
application never having to access the Oracle database again.
Is there one Oracle DB or are there several and which one needs to be
determined based on the user or some other criteria? The article you
link to talks about the latter.
It it’s just one DB and you have one or more tables to be ‘statically’
connected to that DB , then see
http://rails.rubyonrails.com/classes/ActiveRecord/Base.html and look
for the section “Connection to multiple databases in different models”
You probably want to call establish_connection with the right
connection parameters for the table(s) to be connected to the oracle
DB in your config/environment.rb file in a config.after_initialize
block. If you’ve got several tables you can make an abstract AR class
for those models to subclass, and establish the connection for the
abstract class which will take care of the subclass.
I’m working on a project right now which does something similar. One
thing I’ve found is that most of the testing infrastructure of rails
doesn’t really handle tables with their own connections very well,
what I’ve done is to put analogs of those tables directly in the main
test environment database. I wrote the migrations for the ‘external’
tables so that they only actually create the tables if
ENV[‘RAILS_ENV’] is ‘test’
My blog on Ruby