1
0
Fork 0
mirror of https://github.com/paper-trail-gem/paper_trail.git synced 2022-11-09 11:33:19 -05:00

Fix tests and update readme.

This commit is contained in:
Andy Stewart 2011-09-29 11:00:13 +02:00
parent 0a8af1983b
commit 14383f4cb6
2 changed files with 17 additions and 2 deletions

View file

@ -456,7 +456,17 @@ You can store arbitrary model-level metadata alongside each version like this:
end
end
PaperTrail will call your proc with the current article and store the result in the `author_id` column of the `versions` table. (Remember to add your metadata columns to the table.)
PaperTrail will call your proc with the current article and store the result in the `author_id` column of the `versions` table.
N.B. You must also:
* Add your metadata columns to the `versions` table.
* Declare your metadata columns using `attr_accessible` like this:
# config/initializers/paper_trail.rb
class Version < ActiveRecord::Base
attr_accessible :author_id, :word_count, :answer
end
Why would you do this? In this example, `author_id` is an attribute of `Article` and PaperTrail will store it anyway in serialized (YAML) form in the `object` column of the `version` record. But let's say you wanted to pull out all versions for a particular author; without the metadata you would have to deserialize (reify) each `version` object to see if belonged to the author in question. Clearly this is inefficient. Using the metadata you can find just those versions you want:
@ -472,7 +482,7 @@ You can also store any information you like from your controller. Just override
end
end
Remember to add those extra columns to your `versions` table ;)
Remember to add those extra columns to your `versions` table and use `attr_accessible` ;)
## Diffing Versions

View file

@ -47,3 +47,8 @@ def change_schema
end
ActiveRecord::Migration.verbose = true
end
class Version < ActiveRecord::Base
attr_accessible :created_at, :updated_at,
:answer, :action, :question, :article_id, :ip, :user_agent
end