Skip to content

Instantly share code, notes, and snippets.

@alex700
Last active December 21, 2023 00:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alex700/906bd3bf850e130ea69d8cc78d3d3f00 to your computer and use it in GitHub Desktop.
Save alex700/906bd3bf850e130ea69d8cc78d3d3f00 to your computer and use it in GitHub Desktop.
List Ruby on Rails models
# Open rails console `rails c` and run the command:
ActiveRecord::Base.descendants.map(&:name).each { |name| puts name }
# Alternatively, list classes that extend ActiveRecord::Base or any other class the application might use as a base model
ObjectSpace.each_object(Class).select { |klass| klass < ActiveRecord::Base }.map(&:name).sort
# For docker-based apps
docker exec -it [your_container_name] rails runner "ActiveRecord::Base.descendants.each { |model| puts model.name }"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment