Sha256: ae87406d33798a3df6f4720d329c0f367d1ecb30bb2435dc966796cb3a3a25db
Contents?: true
Size: 1.7 KB
Versions: 1
Compression:
Stored size: 1.7 KB
Contents
Introduction ============ Connection Ninja is a really simple gem to help connection to multiple databases. I wrote it to help with the way we were connected a new application at work to our older application that holds the data we needed to do reporting on. We have code (models) that is shared between those two applications, and I wanted them to be able to connect to the correct database regardless which app they were in, and therefore which database.yml they were reading. Installation ============ Due to hopefully everyone upgrading to rails 3, if you need to use this with Rails 2.x just install the old version. Install the gem: Rails 2.x ========= gem install connection_ninja -v 0.3.5 Rails 3 ======= gem install connection_ninja Configuration ============= class MyModel < ActiveRecord::Base use_connection_ninja(:database) end After your normal configuration in database.yml add a new group: database: development: adapter: postgresql database: database_name user: username test: adapter: postgresql database: database_name user: username production: adapter: postgresql database: database_name user: username WHY? === Pure laziness. Rather than putting together a hash you can just call a group with use_connection_ninja(:group) How I used it ============= To get my 20 or 30 models to all use one connection I used a simple abstract class to do it. I also got to learn about these along the way class OtherConnection < ActiveRecord::Base self.abstract_class = true use_connection_ninja(:database) end So I could: class ModelFromOtherDB < OtherConnection end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
connection_ninja-0.4.1 | README.markdown |