How to get nice formatting in the Rails console

前端 未结 12 1469
一生所求
一生所求 2020-12-12 10:50

I want to get something like this to look nice:

>> ProductColor.all
=> [#

        
12条回答
  •  长情又很酷
    2020-12-12 11:12

    You should try hirb. It's a gem made to to pretty format objects in the ruby console. Your script/console session would look like this:

    >> require 'hirb'
    => true
    >> Hirb.enable
    => true
    >> ProductColor.first
    +----+-------+---------------+---------------------+---------------------+
    | id | name  | internal_name | created_at          | updated_at          |
    +----+-------+---------------+---------------------+---------------------+
    | 1  | White | White         | 2009-06-10 04:02:44 | 2009-06-10 04:02:44 |
    +----+-------+---------------+---------------------+---------------------+
    1 row in set
    => true
    

    You can learn more about hirb at its homepage.

提交回复
热议问题