ActiveAudit

Audit support for Active Record

Install

Include ActiveAudit in your Gemfile

gem 'activeaudit', :git=>'https://github.com/maintux/activeaudit.git'

and update your bundle

bundle install

Then run the task to generate migration

rake active_audit_rails_engine:install:migrations

and execute migration

rake db:migrate

Update from 0.1.2 to 0.1.3

You have to installa new migration:

rake active_audit_rails_engine:install:migrations
rake db:migrate

Usage

In your model you have to include the mixin

include ActiveAudit::Logger

This mixin allow you to use an helper called loggable_event that define what you want to log.

The basic syntax is:

loggable_event create: true
loggable_event destroy: true
loggable_event update: true

With this, ActiveAudit will log events using the standard callbacks after_create, after_update and before_destroy

If you want customize the fields that determine the logging action, you can use the Array syntax like the following example:

loggable_event update: [:name,:surname]

So with this syntax, ActiveAudit will log the update event only if name OR surname fields are changed.

You can also specify the value that a field must have to trigger the logging:

loggable_event update: [{state: "confirmed"}]

In this case ActiveAudit will log the update event only if state field is changed and the new value is “confirmed”

It’s possible to use custom event name that is managed like an update event. For exaple you can create an event called confirmation like this:

loggable_event confirmation: [{state: "confirmed"}]

Contributing to ActiveAudit

Copyright © 2013 Massimo Maino. See LICENSE.txt for further details.