Created
August 23, 2008 17:43
-
-
Save joevandyk/6933 to your computer and use it in GitHub Desktop.
How to create ActiveRecord classes on the fly
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
def create_activerecord_class table_name | |
Class.new(ActiveRecord::Base) do | |
set_table_name table_name | |
end | |
end | |
# I already have a users db table | |
# So in the console... | |
>> AnotherUser = create_activerecord_class(:users) | |
=> AnotherUser(id: integer, first_name: string, last_name: string, ...... ) | |
>> AnotherUser.count | |
=> 29605 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment