What is the best way to keep record editing history with Rails and ActiveRecord

What is the best / cleanest / easiest way to keep a record history of entries in Rails?

I am looking for registration - who made the changes and when and the opportunity to roll back to earlier versions of the records.

I assume that you will use ActiveRecord callbacks for updates or deletions, instead of updating / deleting records, you should create a new one and have some kind of identifier to support the same β€œrecord”, maybe a field to distinguish which record is current and version field.

I vaguely remember seeing some plugins, but I can not find them at the moment. r

(Is there a term for this that I do not know?)

+4
source share
3 answers

act_as_audited wins hands. You can even use act_as_versioned with it. The plugin page explains everything. Read the discussion comments below the post on the page. The developers published problems and received positive feedback from the author and others.

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

Here is a preview from the plugin page:

act_as_audited - an active record plugin that logs all changes to your models in the audit table. This uses a polymorphic link to store the audit report for any of the model objects that you want to audit. An audit trail stores the model that the change was, the "action" (create, update, destroy), a serialized hash of the changes, and possibly the user who completed the action.

+10
source

The answers here are good, but some updates are needed.

act_as_audited renamed to audit, see https://github.com/collectiveidea/audited . I have used it with great success.

paper_trail may also be of interest. http://railscasts.com/episodes/255-undo-with-paper-trail version recovery is a bit awkward and undocumented in verified / act _as_audited. paper_trail has clearer examples for this aspect.

+5
source

act_as_versioned should do what you are looking for - http://wiki.rubyonrails.org/rails/pages/ActsAsVersioned

+3
source

All Articles