Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Connections are created via ActiveRecord::Base.establish_connection and retrieved by ActiveRecord::Base.connection. All classes inheriting from ActiveRecord::Base will use this connection. What if you want some of your models to use a different connection? You can add class-specific connections.
For example, let’s say you need to access data residing in a legacy database apart from the database used by the rest of your Rails application. We’ll create a new base class that can be used by models that access legacy data. Begin by adding details for the additional database under its own key in database.yml. Then call establish_connection to make LegacyProjectBase and all its subclasses use the alternate connection instead.