A simple(r) auditing / version tracking library for Rails (ActiveRecord). Developed and tested for Rails 3.2 onwards. Should work with earlier Rails 3 versions but no guarantee. Should be easy to tweak it though.
http://rubydoc.info/gems/auditable/fi…

Almost all of them are outdated and not working with Rails 3.2.2. Some of the popular ones such as papertrail and vestal_versions have many issues and pull requests but haven't been addressed or merged. Based on the large number of forks of these popular gems, people seem to be OK with their own gem tweaks. Some tweaks are good, but some are too hackish (to deal with recent Rails changes) based on the commits that I have read. I have tried some of the more popular ones but they don't work reliably for something simple I'm trying to achieve.

Many of these gems have evolved overtime and become rather (very) cumbersome.

Most or all of them don't seem to support beyond the database columns, i.e. not working (or working well) with virtual methods or associations. papertrail supports has_one but the author said it's not easy to go further than that.

I need something simple and lightweight.

A lot of the gems in the above category are great. I'm just aiming to create a dead simple gem that lets you easily diff the changes on a model's attributes or methods. Yes, methods, not just attributes. Here's the key difference in my approach:

If you want to track changes to complicated stuff such as associated records, just define a method that returns some representation of the associated records and let auditable keeps track of the changes in those values over time.

Basically:

I don't want the default to track all my columns. Only the attributes or methods I specify please.

I don't want to deal with association mess. Use methods instead. Nothing prevents you from saving taking json snapshots; just diff them later.

I care about tracking the values of certain virtual attributes or methods, not just database columns.

I want something simple, similar to ActiveRecord::Dirty#changes but persistent across saves. See the usage of {Auditable::Auditing#audited_changes} below.

See examples under {file:README.md#Usage Usage} section. Please check the {file:CHANGELOG.md} as well.

Installation

Add this line to your application's Gemfile:

gem 'auditable'

And then execute:

$ bundle

Or install it yourself as:

$ gem install auditable

Usage

First, add the necessary audits table to your database with:

rails generate auditable:migration
rake db:migrate

Then, provide a list of methods you'd like to audit to the audit method in your model.

changed_by: [Symbol] Method to call to set the created_by model. Defaults to :user

version: [Boolean or Symbol] If true, the auto incremented version column is used to determine ordering of audits. If a Symbol, the callback is used to generate the version id. Default is to use timestamps.

Demo

I'm going to demo with the test models from the test suite. You probably want to use rails console and test with the model that you want to audit.

For more details, I suggest you check out the test examples in the spec folder itself.

It guessable from the above that audits.modifications will just be a serialized representation of keys and values of the audited attributes.

Who changed it and what was that action?

If you want to store the user who made the changed to the record, just assigned it to the record's changed_by attribute, like so:

# note `attr_accessor :changed_by` is defined in your Survey class by the gem
>> @survey.update_attributes(:changed_by => current_user) # and other attributes you want to set)
# then @surveys.audits.last.user will be set to current_user
# also works when you set changed_by and call save later, of course

action will just be create or update depending on the operation on the record, but you can also override it with another virtual attribute, call it change_action