Rails with multiple databases
code In database.yml
slave1:
host: 18.48.43.29 # your slave’s IP
database: production
username: root
password: pass
l Define a model Slave1.rb
class Slave1 < ActiveRecord::Base
self.abstract_class = true
establish_connection :slave1
end
When you need to run a query on the slave, just do
Slave1.connection.execute("select * from some_table")
Magic Multi-Connections Ruby on Rails ActiveRecords
No comments :
Post a Comment