Skip to content

Instantly share code, notes, and snippets.

@EskiMag EskiMag/multi_db.rb
Created May 19, 2010

Embed
What would you like to do?
module UseMultiDB
def use_db(db_name, options={})
begin
establish_connection "#{db_name}_#{RAILS_ENV}"
set_table_name options[:table_name] unless options[:table_name].blank?
self.inheritance_column = '_sti_type_disabled' unless options[:sti]
rescue
Rails.logger.info "ERROR unable to establish connection to database '#{db_name}_#{RAILS_ENV}'"
end
end
end
ActiveRecord::Base.extend UseMultiDB
# USAGE
#
# class SomeClassInOtherDB < ActiveRecord::Base
# use_db :other_db, :table_name => :weird_name, :sti => false
# end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.