I would like to store some debug messages on an object as it can go through processing but I don't want to be storing this to the database. Is something like this a reasonable way, an instance variable wrapped in a method with a nil guard? Or is there a better way / pattern?
class Bid < ApplicationRecord
...
def debug_reasons
@debug_reasons ||= []
end
...
and then
bid.debug_reasons << "here is a reason"
What you're looking for is attribute
class Bid < ApplicationRecord
attribute :debug_reasons, :default => []
end
More info on attribute
http://api.rubyonrails.org/v5.0/classes/ActiveRecord/Attributes/ClassMethods.html#method-i-attribute
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With