TL;DR: How can one skip changes between nil
and blank
in paper_trail?
I use https://github.com/airblade/paper_trail to log data changes in several ActiveRecord
objects. Some changes are useless from my customers' point of view, so I need to ignore all changes between nil
and blank
(empty string).
paper_trail
doesn't seem to have such option. You can skip certain fields with :skip
option. Can you pass in a Proc that would "decide" to skip changes conditionally?
Your can add a proc to define a new version should be saved or not, the code should be:
class ExampleModel < ActiveRecord::Base
has_paper_trail :if => Proc.new { |t| t.attr_1.present? && t.attr_2.present? }
end
By the way :unless
was also supported! This works for PaperTrail >= 4.0
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