Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'rubygems'
- require 'active_record'
- ActiveRecord::Base.establish_connection(
- :adapter => 'mysql',
- :database => 'forumreader_development',
- :username => 'root',
- :password => '',
- :host => 'localhost'
- )
- #Make a class for each table in the database
- ActiveRecord::Base.connection.tables.each do |table|
- #Create a subclass of active record with the singular name of the
- #the table.
- klass = Class.new(ActiveRecord::Base) do
- @name = table.singularize.capitalize
- end
- #Explicitly set the name of the table just incase pluralization would fails.
- klass.set_table_name table
- #Register a constant for each class that is the
- #capitalized singularization of the table name
- Object.const_set table.singularize.capitalize, klass
- end
- forums = Forum.find(:all, :select => [:title])
- puts forums.first.attribute_names
Add Comment
Please, Sign In to add comment