Rails c output formatting Gem hirb

Formatting Rails c Output with Gem hirb

Notes about the Gem 'hirb' that nicely formats the output of Rails c. By default, the Ruby on Rails console outputs JSON as text when you execute SQL with ActiveRecord using commands like <code>Model.all</code>, but the gem 'hirb' formats the model output nicely.

Shou Arisaka
1 min read
Oct 13, 2025

By default, the Ruby on Rails console outputs JSON as a one-line text when you execute SQL with ActiveRecord using commands like Model.all, which is very hard to read.

The gem โ€œhirbโ€ nicely formats the model output like this:

Hashmodel.all
  Hashmodel Load (0.5ms)  SELECT "hashmodels".* FROM "hashmodels"
+----+----------+------------+------+----------+-------+---------+-------------------------+-------------------------+
| id | title    | content    | vote | favorite | views | user_id | created_at              | updated_at              |
+----+----------+------------+------+----------+-------+---------+-------------------------+-------------------------+
| 1  | title.   | content.   |      |          |       | 1       | 2018-04-28 10:12:29 UTC | 2018-04-28 10:12:29 UTC |
| 2  | title._2 | content._2 |      |          |       | 1       | 2018-04-28 10:13:31 UTC | 2018-04-28 10:13:31 UTC |
| 3  | title.   | content.   |      |          |       | 2       | 2018-04-28 10:14:47 UTC | 2018-04-28 10:14:47 UTC |
+----+----------+------------+------+----------+-------+---------+-------------------------+-------------------------+
3 rows in set

How to Use

  1. Add to Gemfile:
group :development, :test do
  gem 'hirb'         
  gem 'hirb-unicode' 
end
  1. bundle install
  2. After opening the irb console with rails c, run the Hirb.enable command to activate the gem.

In this state, if you run commands like User.all, the output will be nicely formatted.

  • Reference

http://ruby-rails.hatenadiary.com/entry/20141024/1414160189

Share this article

Shou Arisaka Oct 13, 2025

๐Ÿ”— Copy Links