Skip to content

Instantly share code, notes, and snippets.

@rubiety
Forked from qrush/gist:29315
Created November 26, 2008 14:35
Show Gist options
  • Save rubiety/29404 to your computer and use it in GitHub Desktop.
Save rubiety/29404 to your computer and use it in GitHub Desktop.
# If you ever needed an array of all ActiveRecord models in your Rails app (+ Session):
Dir["app/models/**/*.rb"].each {|r| require r}
subclasses_of(ActiveRecord::Base).map(&:class_name)
# Or *all* models:
ActiveRecord::Base.connection # Preloads driver constants
constants_before = Object.constants
Dir["app/models/**/*.rb"].each {|r| require r}
Object.constants - constants_before
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment