让 Rails Console 中的返回结果以表格显示

hirb 加入 Gemfile:

gem 'hirb'

用 Bundler 安装:

$ bundle

进 Rails Console :

$ rails c
> require 'hirb'
=> false
> Hirb.enable
=> true

现在 Model 返回的查询结果将以表格的方式显示。比如用 Client Model 查询:

> Client.all
  Client Load (11.3ms)  SELECT "clients".* FROM "clients" ORDER BY created_at ASC
+----+-------------------+-------------------------+-------------------------+
| id | name              | created_at              | updated_at              |
+----+-------------------+-------------------------+-------------------------+
| 1  | The First Client  | 2012-01-13 12:25:22 UTC | 2012-01-13 12:25:22 UTC |
| 2  | The Second Client | 2012-01-13 12:25:31 UTC | 2012-01-13 12:25:31 UTC |
+----+-------------------+-------------------------+-------------------------+
2 rows in set