I use a gem called switch_point, It's written only briefly in the readme, and it's difficult to understand because no example is shown, but it seems that you can use switch_point_proxy.model_for_connection.
https://github.com/eagletmt/switch_point
For example, in the User model
use_switch_point :slave
Add like
rows = []
User.with_readonly do
con = User.switch_point_proxy.model_for_connection.connection
sql = "select * from users limit 1"
rows = con.select_all(sql)
end
It seems that you can go like
Recommended Posts