Hide (abbreviate) certain columns when viewing model instances in Rails console

Asked 2 years ago, Updated 2 years ago, 123 views

There is a model that uses serialize to save Array, but the array part is a little big, and when I view it in the Rails Console, other columns flow quickly, making it very difficult to handle.

 foo=Foo.fisrt
# <Foo:0x0000000000000>{
    : id=>1,
    # It's hard to use because the display here quickly flows.
    :serialized_column=>[
      # an array that is about the amount of a terminal screen
    ]
}

This is what the condition looks like.

I wanted to prevent this serialized_column from being displayed unless I explicitly called it. Is there any way?

I thought I should overwrite inspect, but it seems to be called in a different way, so there was no change in the override.
Also, I want to make sure that even if I overwrite it, it only affects the development environment.

ruby-on-rails console

2022-09-29 20:24

1 Answers

A gem called Hirb can shape record output.

I don't have data like serialized_column, so I haven't confirmed it yet, but I might be able to adjust it.

https://github.com/cldwalker/hirb


2022-09-29 20:24

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.