# Help please - Trying to connect to a user defined database

**URL:** <https://www.ruby-forum.com/t/help-please-trying-to-connect-to-a-user-defined-database/120048>\
**Category:** Rails\
**Created:** [November 13, 2007, 11:28am UTC](https://www.ruby-forum.com/t/help-please-trying-to-connect-to-a-user-defined-database/120048 "2007-11-13T11:28:51Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![chilaquil](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/fbc32d/32.png) [@chilaquil](https://www.ruby-forum.com/u/chilaquil)\
**Post date:** [November 13, 2007, 11:28am UTC](https://www.ruby-forum.com/t/help-please-trying-to-connect-to-a-user-defined-database/120048/1 "2007-11-13T11:28:51Z")

</div>

Hi,

I’m stuck on the following problem. Using a legacy system, we have  
multiple databases to need to connect to. I solved this problem using  
the use\_db plugin, as most of the information is just in two databases.

However, I now need to connect to a number of databases, called by the  
user.

I could do this by hard coding each and every database into  
database.yml, but this would seriously defeat DRY principles, as for  
these databases they are all hosted on the same host and port. I also  
want them all to be using a foo connection

Example

foo\_development  
adapter: some\_adapter  
database: wibble  
username: read\_only  
password: xxxxx  
host: this\_one  
port: 3333

foo\_development  
adapter: some\_adapter  
database: snark  
username: read\_only  
password: xxxxx  
host: this\_one  
port: 3333

foo\_development  
adapter: some\_adapter  
database: boom  
username: read\_only  
password: xxxxx  
host: this\_one  
port: 3333

I am rather stuck on trying to use ERb to only use a user defined  
database name, both attempting a global variable, and method defined in  
the base class model.

Any help here would be much appreciated.

Cheers

Andy
