Table Print on Rails Console

TablePrint shows objects in nicely formatted columns for easy reading. It even lets you nest other tables of related objects, contextualizing data across tables. It's incredibly flexible, yet simple, making it easy to see exactly the data you care about.


Install as a standalone gem

$ gem install table_print

Or install within rails
In your Gemfile:

gem "table_print"

$ bundle install


Outside rails
$ irb

> require 'table_print'
> tp array_of_objects, options

Inside rails, the gem has already been required by your Gemfile so all you need to do is
$ rails c

> tp array_of_objects, options

You should see something like this:

table print on console

TablePrint tries to use sensible defaults to choose the columns to show. If you're inspecting ActiveRecord objects, it uses the ActiveRecord column names. You can customize the output to show fewer columns, or show other methods you've written on your model. Use symbols or strings to reference the columns.

You can reference nested objects with the method chain required to reach them. Say you had some users who wrote books, and those books had photos.

table print with association on console


On ubuntu terminal for too much columns tables it get wrapped and not display well and it might be confusion to identify which data is belongs to which columns.

wrapped table print

If you have any suggestion for this post then welcome