acts_as_audited is an ActiveRecord extension that logs all changes to your models in an audits table.
Switch branches/tags
Clone or download
Pull request Compare This branch is 494 commits behind collectiveidea:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


= acts_as_audited

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

The purpose of this fork is to add comments to audits.

== Installation

    script/plugin install git://

* Generate the migration

  * If installing without a previous version of acts_as_audited or you do not mind overwriting your audits table:

      script/generate audited_migration add_audits_table

  * If upgrading from a version of acts_as_audited that does not contain comment functionality:

      script/generate audited_migration_update update_audits_table

  * After running one of the generators:

      rake db:migrate

== Usage

Declare <tt>acts_as_audited</tt> on your models:

    class User < ActiveRecord::Base
      acts_as_audited :except => [:password, :mistress]
Within a web request, will automatically record the user that made the change if your controller has a <tt>current_user</tt> method. Comments can be added to an audit by setting model.audit_comments 
before create/update/destroy. If the :comment_required option is given to acts_as_audited, 
the save/update/destroy action will fail with add an error on model.audit_comment and triggering a 
transaction rollback if model.audit_comment is nil.

To record a user in the audits outside of a web request, you can use <tt>as_user</tt>:

    Audit.as_user(user) do
      # Perform changes on audited models

== Parent record tracking

To track the parent record of the record being audited, you pass an optional parent option in the model being audited:

    class Author < ActiveRecord::Base
      has_many :books
    class Book < ActiveRecord::Base
      belongs_to :author
      acts_as_audited :parent => :author

Each audit entry on a book will be associated to an author through <tt>auditable_parent</tt>, and each author will have a <tt>book_audits</tt> association for tracking the collective changes to an authors' books. This becomes really valuable to track when a book has been removed from the catalog.

The association name on the parent is built using the singular of the <tt>has_many</tt> association name, with <tt>_audits</tt> appended, in the example yielding <tt>book_audits</tt> and not <tt>books_audits</tt>.

== Caveats

If your model declares +attr_accessible+ after +acts_as_audited+, you need to set +:protect+ to false. acts_as_audited uses +attr_protected+ internally to prevent malicious users from unassociating your audits, and Rails does not allow both +attr_protected+ and +attr_accessible+. It will default to false if +attr_accessible+ is called before +acts_as_audited+, but needs to be explicitly set if it is called after.

  class User < ActiveRecord::Base
    acts_as_audited :protect => false
    attr_accessible :name

== Compatability

acts_as_audited works with Rails 2.1 or later.

== Getting Help

Join the mailing list for getting help or offering suggestions:

== Contributing

Contributions are always welcome. Checkout the latest code on GitHub:

Please include tests with your patches. There are a few gems required to run the tests:
  $ gem install multi_rails
  $ gem install thoughtbot-shoulda jnunemaker-matchy --source

Make sure the tests pass against all versions of Rails since 2.1:

  $ rake test:multi_rails:all

Please report bugs or feature suggestions on GitHub: