Skip to content

Instantly share code, notes, and snippets.

@Kalaivanimurugan
Last active December 1, 2023 21:13
Show Gist options
  • Star 16 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save Kalaivanimurugan/61b60e4dcf3d0ed49873761cad7f660f to your computer and use it in GitHub Desktop.
Save Kalaivanimurugan/61b60e4dcf3d0ed49873761cad7f660f to your computer and use it in GitHub Desktop.
List all model names in rails console
Rails.application.eager_load!
ActiveRecord::Base.descendants # It returns all models and its attributes.
ApplicationRecord.descendants.collect(&:name) # It returns only the model names
@nidnogg
Copy link

nidnogg commented Nov 14, 2023

In case someone is using legacy Ruby on Rails (v4.2.5 and below) to get just the model names,
ActiveRecord::Base.descendants.collect(&:name)
should work instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment