I am running into an issue when trying to reify PaperTrail versions after removing a column from the model's table.
The stacktrace begins: private method 'warn' called for nil:NilClass
and points me to the following lines inside of the reify
method:
# Set all the attributes in this version on the model.
attrs.each do |k, v|
if model.has_attribute?(k)
model[k.to_sym] = v
elsif model.respond_to?("#{k}=")
model.send("#{k}=", v)
else
logger.warn "Attribute #{k} does not exist on #{item_type} (Version id: #{id})."
end
end
Because I have removed the column from the table, I am landing in the else
block of the logic tree, which seems perfectly reasonable... I am fine logging this out moving on with the reification.
However, I don't understand why logger
is nil
in the first place. Where and how can I set the PaperTrail logger so that we simply log the behavior instead of crashing the app?
As of 2016-12-14 the answer is to upgrade to PT 6.0.2.
This was fixed in PT 6.0.2, thanks to PR https://github.com/airblade/paper_trail/pull/905 by Andy (the OP. Thanks, Andy)