Connecting to multiple databases in rails in one application

The command you are looking for is establish_connection. You might want to look at the rails rdoc. Search for "Connection to multiple databases in different models" in http://api.rubyonrails.com/classes/ActiveRecord/Base.html.

eg:

class SomeModelDB1 < ActiveRecord::Base   self.establish_connection("db1") end

class SomeModelDB2 < ActiveRecord::Base   self.establish_connection("db2") end

database.yml db1:   adapter: mysql   database: somedb   username: user   password: pass   host: localhost   socket: /tmp/mysql.sock db2:   adapter: mysql   database: somedb2   username: user   password: pass   host: remotehost