For a project I\'m currently working on I need to implement object versioning. Unfortunately I need to keep a full history of each object, so a single table solution like Paper
I've been using Vestal Versions, a rails gem/plugin that uses the memento pattern to create a history table, and it saves a diff of attributes in after_save and after_destroy callbacks.
It also records when it was changed and increments a version number so you can rollback to a certain version or a version present at a certain date or time.
I can then pull up an object like so:
@user = User.last
@user.versions.last.changes #=> {:name => ['Robert','Bob']}
I'm a pretty big fan.
You can specify custom version subclasses with the :class_name option:
class Post < ActiveRecord::Base
has_paper_trail :class_name => 'PostVersion'
end
class PostVersion < Version
# custom behaviour, e.g:
self.table_name = :post_versions # in rails 2, use set_table_name
end
This allows you to store each model's versions in a separate table, which is useful if you have a lot of versions being created.