Last active
December 1, 2023 21:13
-
-
Save Kalaivanimurugan/61b60e4dcf3d0ed49873761cad7f660f to your computer and use it in GitHub Desktop.
List all model names in rails console
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
Rails.application.eager_load! | |
ActiveRecord::Base.descendants # It returns all models and its attributes. | |
ApplicationRecord.descendants.collect(&:name) # It returns only the model names |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.