Rails: List Objects Using Rails Console
I was looking for a way to get a collection of every model using the Rails console. Here are a few simple ways to do it.
Step 0
If you do not have Ruby on Rails installed, please read this tutorial
Step 1
Run Rails Console.
rails c
Step 2
Raw list of tables
ActiveRecord::Base.connection.tables
Clean list of names
ApplicationRecord.descendants.collect { |type| type.name }
If you are in development mode, you might need to add this first.
Rails.application.eager_load!
Clean list of names. This is my favorite.
ActiveRecord::Base.descendants.map {|type| puts type}
Detailed list of models with parameters.
ActiveRecord::Base.connection.tables.map{|x|x.classify.safe_constantize}.compact