Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
90 lines (56 sloc) 3.27 KB
= d5/acts_as_audited
d5/acts_as_audited is just a forked version of acts_as_audited. Instead of storing changes as a hash inside a column, an audit_changes table was made.
This also allowed for associations to be handled. See usage for more information about that.
= 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 store both the previous values and the changed value, making each audit record selfcontained.
== Installation
* Install the plugin into your rails app
If you are using Rails 2.1:
script/plugin install git://
For versions prior to 2.1:
git clone git:// vendor/plugins/acts_as_audited
* Generate the migration
script/generate audited_migration add_audits_table
rake db:migrate
== Usage
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 <tt>current_user</tt> method.
class ApplicationController < ActionController::Base
audit User, List, Item => {:except => :password, :include => [:subitems]}
def current_user
@user ||= User.find(session[:user])
To get auditing outside of Rails you can explicitly declare <tt>acts_as_audited</tt> on your models:
class User < ActiveRecord::Base
acts_as_audited :except => [:password, :mistress], include => [:items, :lists]
To record a user in the audits when the sweepers are not available, you can use <tt>as_user</tt>:
Audit.as_user( user ) do
# Perform changes on audited models
See for more information.
== 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
=== ActiveScaffold
Many users have also reported problems with acts_as_audited and ActiveScaffold, which appears to be caused by a limitation in ActiveScaffold not supporting polymorphic associations. To get it to work with ActiveScaffold:
class ApplicationController < ActionController::Base
audit MyModel, :only => [:create, :update, :destroy]
== Compatability
acts_as_audited works with Rails 2.1 or later.
== 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: