Skip to content

Instantly share code, notes, and snippets.

@mattraibert
Created November 2, 2012 04:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattraibert/3998717 to your computer and use it in GitHub Desktop.
Save mattraibert/3998717 to your computer and use it in GitHub Desktop.
Turn your tables into active record models
require 'active_record'
ActiveRecord::Base.establish_connection({:adapter => "mysql2", :username => "root", :password => "", :database => "hayuge_development"})
def show_tables
ActiveRecord::Base.connection.tables
end
def to_model_name table_name
table_name.split(?_).map(&:capitalize).join
end
show_tables.each do |table|
eval %Q|class #{to_model_name table} < ActiveRecord::Base
self.table_name = '#{table}'
end|
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment