acces multiply databases?


i build my own rails-app, with "my" (own)database for a new website. My
company has a big central database (also mysql> same server > cluster >
but no rails-app) with some interesting content i want to use...customer
reviews, faq, country/city-descriptions ect.

How can i use this data in my app?

Some requirements

I want to load the cities-data from the central database in my rails-app
and then use Acts As Taggable to do some tagging on the cities.



Rails' ActiveRecord objects share the db connection of the ARec object
from which they inherit. Normally, it's ActiveRecord::Base and all
the ARec classes share the same connection. You can take advantage of
this to accomplish what you're wanting to do...

class CompanyConnection < ActiveRecord::Base
  self.abstract_class = true
  establish_connection "company_#{RAILS_ENV}".to_sym

The class above will allow you to define three new db connections in
database.yml called company_development, company_test, and
company_production where you can define the connection to your
company's db. Then, you can create classes that inherit from *this*
class that access your company DB (by default the others will still
refer to your db... or the ones defined by development, test, and
production in database.yml).

With the examples above...

class Tags < ActiveRecord::Base

class Cities < CompanyConnection