PaperTrail Ignore vs Skip

:skip attribute/key was released in PaperTrail 2.4.1 What are the differences between :ignore and :skip? For example we have Article model with ignored title field and skipped file_upload field:

1
2
3
4
class Article < ActiveRecord::Base
  has_paper_trail :ignore => :title,
                  :skip   => :file_upload
end

Create empty article object, initial version’ll be created:

1
2
3
4
5
>> a = Article.create
>> Article
=> Article(id: integer, title: string, content: string, file_upload: string)
>> a.versions.count
=> 1

If we update ignored title attribute, version won’t be created. If we update non-ignored content column, version’ll be created and we’ll have stored changes of object in object_changes column that available through changeset attribute.

1
2
3
4
5
6
7
8
9
10
>> a.update_attributes :title => 'Title'
>> a.versions.count
=> 1
>> a.update_attributes :title => 'New Title', :content => 'Content'
>> a.versions.count
=> 2
>> a.versions.last.changeset
=> {"content"=>[nil, "Content"]}
>> a.versions.last.reify
=> #<Article id: 1, title: "Title", content: nil, abstract: nil, file_upload: nil>

As we see ignored title column not stored in changeset but it stored in dumped object. But there are some cases when we don’t need to store some columns in dump object by various reasons. For these cases :skip key has been created. :skip and :ignore work identically, but :skip doesn’t store data of skiped columns in object dump. That’s it.

Information about attributes tracking you can find in paper_trail PaperTrail README (Choosing Attributes To Monitor) on GitHub.

Issue about :skip on GitHub.

Peace!

Comments