Skip to content

Instantly share code, notes, and snippets.

@cj
Created December 8, 2011 17:08
Show Gist options
  • Save cj/1447638 to your computer and use it in GitHub Desktop.
Save cj/1447638 to your computer and use it in GitHub Desktop.
ActiveRecord::Base.class_eval do
def self.set_table_name(value = nil, &block)
db_nick, table = self.name.downcase.split('::')
new_value = "#{ ActiveRecord::Base.configurations[db_nick]['database']}.#{value}"
define_attr_method :table_name, new_value, &block
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment