Chris Mendez in For Developers, Ruby

Ruby on Rails: List Objects Using Rails Console

I was looking for a way to get a collection of every model using Rails console. Here are a few simple ways to do it.

Step 1

Run Rails Console.

rails c

Step 2

Raw list of tables


Clean list of names

ApplicationRecord.descendants.collect { |type| }

If you are in development mode, you might need to add this first.


Clean list of names. This is my favorite. {|type| puts type}

Detailed list of models with parameters.{|x|x.classify.safe_constantize}.compact