Multiple database connections

Hi,

I’m trying to connect to a second database, but I can’t seem to get it
working.

When a new user gets created in the application, the user data gets
writter to the application database into the users table like all normal
applications. After the user gets created, the application needs to
connect to a second database. The second database is the pureftpd
database where ftp user data gets stored.

The problem is, the pureftpd database has a table called users, and so
does my application, so creating a new model “user” like I have read in
all the sites that give a small tutorial on multiple database
connections is out of the question.

I also tryed using ruby-sequel to handle the second database connection,
but that conflicts with ActiveRecord.

I have never set u multiple connection in one application, so I have no
idea on what doing next, and I was hoping someone could help me out on
this one.

Thank you in advance.

On Jun 1, 11:32 am, Michael R. [email protected]
wrote:

The problem is, the pureftpd database has a table called users, and so
does my application, so creating a new model “user” like I have read in
all the sites that give a small tutorial on multiple database
connections is out of the question.

The following should work (but I haven’t tried it , so it might not).
Create a second class called PureFtpUser (or something like that). In
that model, use set_table_name to set the table used to users and use
establish_connection to tell it to connect to another database. If you
don’t want to pollute your code with the connection details,
ActiveRecord::Base.configurations contains all the configurations
defined in your database.yml, so you can do something like
establish_connection(ActiveRecord::Base.configurations[“pureftp”]

Fred

Thank you for your quick reply. Everything seems to work as you
described, except for the configurations[] part. When I specify the
whole string, it works. But that is something I’ll check out later.

Thank you again for the big help