How to get nice formatting in the Rails console

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

I want to get something like this to look nice:

>> ProductColor.all
=> [#

        
12条回答
  •  时光取名叫无心
    2020-12-12 11:06

    I think this solution is the most accurate one. You should try this:

    puts JSON.pretty_generate Entry.all.map(&:attributes)
    

    This will give you a super nice output compare to YAML format:

    [
      {
        "id": 44,
        "team_id": null,
        "member_id": 1000000,
        "match_id": 1,
        "created_at": "2019-04-09 15:53:14 +0900",
        "updated_at": "2019-04-09 15:53:14 +0900"
      },
      {
        "id": 45,
        "team_id": null,
        "member_id": 1000001,
        "match_id": 1,
        "created_at": "2019-04-09 15:53:36 +0900",
        "updated_at": "2019-04-09 15:53:36 +0900"
      },
      {
        "id": 46,
        "team_id": null,
        "member_id": 1000003,
        "match_id": 1,
        "created_at": "2019-04-09 15:56:40 +0900",
        "updated_at": "2019-04-09 15:56:40 +0900"
      },
      {
        "id": 47,
        "team_id": null,
        "member_id": 1000004,
        "match_id": 1,
        "created_at": "2019-04-09 15:56:48 +0900",
        "updated_at": "2019-04-09 15:56:48 +0900"
      }
    ]
    

提交回复
热议问题