I am using apartment gem where it has multi tenancy. I want to have a solution like whenever that particular model is called or any execution happen it should switch to that specific database.
model name = RakeLog
main db_name = ABC
another db_name = ABC_logs
right now what I have done is created a class method in model
class RakeLog < ActiveRecord::Base
def self.switch_to_log
current = Apartment::Tenant.current
Apartment::Tenant.switch!(current+'_logs')
end
end
what I am doing now is calling this method everywhere when I need to switch to 'logs' db. I want something like whenever this model gets called it should switch to 'logs' db automatically. Any help is appreciated.