Created
November 2, 2012 04:27
-
-
Save mattraibert/3998717 to your computer and use it in GitHub Desktop.
Turn your tables into active record models
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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