Skip to content

Instantly share code, notes, and snippets.

@joevandyk
Created August 23, 2008 17:43
Show Gist options
  • Save joevandyk/6933 to your computer and use it in GitHub Desktop.
Save joevandyk/6933 to your computer and use it in GitHub Desktop.
How to create ActiveRecord classes on the fly
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