Agile Web Development

Build it. Launch it. Love it.

acts_as_audited

acts_as_audited is an ActiveRecord extension that logs all changes to your models in an audits table.

Auditing in Rails

If you’re using acts_as_audited within Rails, you can simply declare which models should be audited. acts_as_audited can also automatically record the user that made the change if your controller has a current_user method.

  class ApplicationController < ActionController::Base
    audit User, List, Item
  protected
    def current_user
      @user ||= User.find(session[:user])
    end
  end

Customizing

To get auditing outside of Rails, or to customize which fields are audited within Rails, you can explicitly declare acts_as_audited on your models:

    class User < ActiveRecord::Base
      acts_as_audited :except => [:password, :mistress]
    end

See http://opensoul.org/2006/07/21/acts_as_audited for more information.

Vitals

Home http://github.com/collectiveidea/acts_as_audited
Repository git://github.com/collectiveidea/acts_as_audited.git
License Rails' (MIT)
Tags Tag_red activerecord actsasaudited audit auditing changes collectiveidea trail
Rating (19 votes)
Owner Brandon Keepers, Collective Idea
Created 1 August 2006

Comments

  • Avatar
    Chirantan
    1 July 2008

    Awesome plugin. I would really like its functionality to be extended for the ActiveResource feature of Rails 2.0.2 though. Is it already implemented?

  • Avatar
    Swards
    6 February 2009

    Acts and Audited and Authlogic appear to have some trouble working together (at least by default) and I'm hoping to find some help.

    When the user access a page, the current_user method is invoked and, with Authlogic, the User object is updated (last_request_at column). This triggers a callback to audit the User object, but this is before current_user (the @current_user variable) is available. This causes an endless look and a stack overflow.

    Any thoughts about how to get around this? I am also asking the authlogic guys if they have any thoughts at:

    http://www.binarylogic.com/2008/11/3/tutorial-authlogic-basic-setup

Add a comment