[ANN] uses_connection plugin


This is a fairly simple but handy plugin that lets you specify which
database connection to use on a per-model basis. It is useful when you
have multiple applications sharing the same data, in other words, this
is just a nicer way of using “Model.establish_connection(database)”.


First create a ‘shared’ database configuration in config/database.yml:

adapter: mysql
database: shared_database
username: user
password: password
host: dbs_host

Next tell your model that it should connect the the ‘shared’ database
and use the table there…

class ZipCode < ActiveRecord::Base

Uses the ‘shared’ database in all environments

uses_connection :shared, :in => :all

… and the next time you do


or any other interaction with the ZipCode model it will use the
zip_codes table in your shared database.

Where to get it:

GitHb: http://github.com/railsfreaks/uses_connection
More info:

Thiago J.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs