Is there a way in the rails console
to display all rails models?
Something like this:
Models.all
which results on this:
[Customer, Site, Page, Download]
Is there a way in the rails console
to display all rails models?
Something like this:
Models.all
which results on this:
[Customer, Site, Page, Download]
Try this:
ActiveRecord::Base.subclasses
This will return an array, so to get the name of the models only, you'd need to run:
ActiveRecord::Base.subclasses.map(&:name)
Just run:
Rails.application.eager_load!
ActiveRecord::Base.subclasses
I tried both the answers above, It does not work as expected. I got this result,
["User", "HABTM_Roles", "ApplicationRecord", "PublicActivity::ORM::ActiveRecord::Activity", "ApplicationRecordGlobal", "HABTM_Users", "UserSync"]
What worked for me was,
Rails.application.eager_load!
ApplicationRecord.subclasses.map(&:name)
if you run rails c
with -e production
, then
ApplicationRecord.subclasses
ApplicationRecord.subclasses.map(&:name)
if you run rails c
in development, you need to run eager_load
before above command
Rails.application.eager_load!
for all models have inherited from ApplicationRecord
and ApplicationRecord
inherited from ActiveRecord::Base
.
and eager_load!
will load all Models, but in development environment eager_load
are false. you can find this config in config/environments/development.rb