views:

486

answers:

2

What is the best/cleanest/easiest way to maintain the edit history of records in Rails?

I'm looking for logging - who made the edits and when and the ability to rollback to earlier versions of records.

My guess is that you would use ActiveRecord callbacks on updates or deletes and instead of updating/deleting records you would create a new one and have some sort of identifier to keep the same "record" associated, maybe a field to distinguish which record is current, and a version field.

I vaguely recall seeing some plugins but I can't seem to find them at the moment.r

(Is there a term for this that I don't know?)

+2  A: 

acts_as_versioned should do what you're looking for - http://wiki.rubyonrails.org/rails/pages/ActsAsVersioned

Chris
+7  A: 

acts_as_audited wins hands down. You can even use acts_as_versioned with it. The plugin-page explains everything. Go through the discussion comments below the post on the page. Developers have posted issues and have obtained positive responses from the author and others.

I have used this plugin in many apps and I find it very very useful. Highly recommended.

Here is a preview from the plug-in page:

acts_as_audited is an Active Record plugin that logs all modifications to your models in an audits table. It uses a polymorphic association to store an audit record for any of the model objects that you wish to have audited. The audit log stores the model that the change was on, the “action” (create, update, destroy), a serialzied hash of the changes, and optionally the user that performed the action.

Chirantan
ah yes. Auditing. I knew there was a word. I just couldn't remember it. Thanks.
srboisvert
:) Welcome. The plug-in is awesome. Very easy to use and does precisely those things that an audit should have. Comes handy while generating reports.
Chirantan