3

I have an image blob written to a field in the db, but I don't want to see that output in a console when I view the user object.

I don't need the output changed or modified for the functioning of the application this is JUST for debugging / developing with the console. I did attempt some of the serialization concepts but they aren't helpful for these purposes. I also looked into filter_parameters which only are helpful for logging and not pry console output.

I am using the pry-rails gem for the rails console, if that changes anything.

trh
  • 7,186
  • 2
  • 29
  • 41

3 Answers3

2

Maybe a bit late to the party, but in current versions of ActiveRecord, the cleanest solution would be to overwrite attribute_for_inspect, e.g.

def attribute_for_inspect(attr_name)
  return 'SKIPPED' if attr_name == :blob

  super
end
Alex
  • 2,398
  • 1
  • 16
  • 30
0

You'll need to override the inspect method for the object. Have a look at the default implementation of inspect - it uses all the object's attributes. You'll have to change that to include only the columns/attributes you want to be shown.

eugen
  • 8,916
  • 11
  • 57
  • 65
0

you can use select to do that

User.select(User.attribute_names - ['avatar', 'permalink']).last

if you use this frequently, i'd suggest you declare a scope for your User class

class User < ActiveRecord::Base
  scope :pry_scope, ->{ select(User.attribute_names - ['avatar', 'permalink']) }
  ...
end

then use it on your console:

> User.pry_scope.last
sa77
  • 3,563
  • 3
  • 24
  • 37