Guest User

Untitled

a guest
Mar 10th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. require 'rubygems'
  2. require 'active_record'
  3.  
  4. ActiveRecord::Base.establish_connection(
  5. :adapter => 'mysql',
  6. :database => 'forumreader_development',
  7. :username => 'root',
  8. :password => '',
  9. :host => 'localhost'
  10. )
  11.  
  12.  
  13. #Make a class for each table in the database
  14. ActiveRecord::Base.connection.tables.each do |table|
  15.  
  16. #Create a subclass of active record with the singular name of the
  17. #the table.
  18. klass = Class.new(ActiveRecord::Base) do
  19. @name = table.singularize.capitalize
  20. end
  21.  
  22. #Explicitly set the name of the table just incase pluralization would fails.
  23. klass.set_table_name table
  24.  
  25. #Register a constant for each class that is the
  26. #capitalized singularization of the table name
  27. Object.const_set table.singularize.capitalize, klass
  28.  
  29. end
  30.  
  31. forums = Forum.find(:all, :select => [:title])
  32. puts forums.first.attribute_names
Add Comment
Please, Sign In to add comment