Changed the way that notable attributes are worked out to make better sense, and updated the readme

This commit is contained in:
Matthew MacLeod 2011-02-25 14:36:32 +00:00
parent c97eee5868
commit 7e34a81edf
2 changed files with 22 additions and 2 deletions

View File

@ -164,7 +164,7 @@ Here's a helpful table showing what PaperTrail stores:
PaperTrail stores the values in the Model Before column. Most other auditing/versioning plugins store the After column.
## Ignoring changes to certain attributes
## Choosing Attributes To Monitor
You can ignore changes to certain attributes like this:
@ -182,6 +182,22 @@ This means that changes to just the `title` or `rating` will not store another v
>> a.versions.length # 2
>> a.versions.last.reify.title # 'My Title'
Or, you can specify a list of all attributes you care about:
class Article < ActiveRecord::Base
has_paper_trail :only => [:title]
end
This means that only changes to the `title` will save a version of the article:
>> a = Article.create
>> a.versions.length # 1
>> a.update_attributes :title => 'My Title'
>> a.versions.length # 2
>> a.update_attributes :content => 'Hello'
>> a.versions.length # 2
Passing both `:ignore` and `:only` options will result in the article being saved if a changed attribute is included in `:only` but not in `:ignore`.
## Reverting And Undeleting A Model

View File

@ -151,7 +151,11 @@ module PaperTrail
end
def notably_changed
self.class.only.empty? ? (changed - self.class.ignore) : (changed & self.class.only)
self.class.only.empty? ? changed_and_not_ignored : (changed_and_not_ignored & self.class.only)
end
def changed_and_not_ignored
changed - self.class.ignore
end
# Returns `true` if PaperTrail is globally enabled and active for this class,