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)”.
Example: ======= First create a ‘shared’ database configuration in config/ database.yml: shared: 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 end ... and the next time you do ZipCode.find(:first) 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: http://railsfreaks.com/2008/5/2/introducing-the-uses_connection-rails-plugin -- Thiago Jackiw http://www.railsfreaks.com --~--~---------~--~----~------------~-------~--~----~ SD Ruby mailing list [email protected] http://groups.google.com/group/sdruby -~----------~----~----~----~------~----~------~--~---
