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
- Add to Gemfile:
group :development, :test do
gem 'hirb'
gem 'hirb-unicode'
end
bundle install- After opening the irb console with
rails c, run theHirb.enablecommand to activate the gem.
In this state, if you run commands like User.all, the output will be nicely formatted.
- Reference