Hello list
I must connect to an outside database for a few simple lookups while creating
records in the database specified in my
''/config/database.yml.'' My only option
is to connect to the outside database in read-only mode.
I can''t seem to peice together what I need to do from the Rails Howto
on
connecting to two different databases
(http://wiki.rubyonrails.com/rails/show/HowtoUseMultipleDatabases).
1. I need to have a form come up and get a few fields, and then create a record.
This works no problem!
Name______
Dcode ____ <-- foriegn key to be used to load records from another database
2. Take the value of one of those submitted fields, connect to a different
database, load a range of matching, related records then populate a popup menu
of choices in part II of a form to complete a record.
Your Plan Choices _____ <-- pop out menu loaded with choices based upon
''Dcode''
I see in the ''Howto Use Multiple Databases'' a method for doing
this
conditionally in a filter, but this is not really what I need to do - I just
need to connect to the outside database, grab some records in to a hash, and
then close the connection - all in a method that would be accessable to a
template or partial in the views. Here is what I think I want to do:
So my best guess is to place a method in
''/app/controllers/abstract_application.rb''
class AbstractApplicationController < ActionController::Base
def get_group_core
ActiveRecord::Base.establish_connection (
:adapter => "sqlserver"
:host => "db.host.net"
:database => "siscSQLtest"
:username => "user"
:password => "password"
)
groupCore = ActiveRecord::Base.connection.select_all (''SELECT FROM
DistPlans
WHERE (DistrcitID = #{Dcode}))
# groupCore should be a hash of arrays
return groupCore
end
I''m thinking this won''t work because it will break the
connection to the
database in my model (plus I am a Ruby newbie so my syntax may be goofy)
Next I need to figure out where and when I can access this so that I can render
it as a part of a second input form for the record I am creating.
Thank you for any shove in the right direction here - I am 100% dedicated to
learning Ruby & Rails and I promiss my questions won;t be so elementary in
the
future.
-Erin
-------------------------------------------------
This mail sent through IMP: http://horde.org/imp/