<commit_before>= acts_as_audited

+acts_as_audited+ is an ActiveRecord extension that logs all changes to your 
models in an audits table, with optional revision comments. +acts_as_audited+
has been updated to work with Rails 3, to use it with older version of Rails,
please see the <tt>rails2</tt> branch.

== Installation

In <tt>Gemfile</tt>:

    gem "acts_as_audited", "2.0.0.rc1"

In your application root, run:

    $ bundle install

Generate the migration:

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

    $ rails g acts_as_audited:install

* If upgrading from a previous version of +acts_as_audited+ you might need some alterations to the audits table:

    $ rails g acts_as_audited:upgrade

* After running one of the generators:

    $ rake db:migrate

== Upgrading

Upgrading to Rails 3, or even between point releases of +acts_as_audited+, might require alterations to the audits table. After every upgrade please run the following generator:

    $ rails g acts_as_audited:upgrade

The upgrade generator will only generate migrations that are missing, or no migrations at all if you are up to date.

== Usage

Declare +acts_as_audited+ on your models:

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

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

To record a user in the audits outside of a web request, you can use +as_user+:

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

== Caveats

If your model declares +attr_accessible+ after +acts_as_audited+, you need to set <tt>:protect</tt> 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
  end

== Compatability<commit_msg>Updated readme for associated audits<commit_after>= acts_as_audited

+acts_as_audited+ is an ActiveRecord extension that logs all changes to your 
models in an audits table, with optional revision comments. +acts_as_audited+
has been updated to work with Rails 3, to use it with older version of Rails,
please see the <tt>rails2</tt> branch.

== Installation

In <tt>Gemfile</tt>:

    gem "acts_as_audited", "2.0.0.rc1"

In your application root, run:

    $ bundle install

Generate the migration:

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

    $ rails g acts_as_audited:install

* If upgrading from a previous version of +acts_as_audited+ you might need some alterations to the audits table:

    $ rails g acts_as_audited:upgrade

* After running one of the generators:

    $ rake db:migrate

== Upgrading

Upgrading to Rails 3, or even between point releases of +acts_as_audited+, might require alterations to the audits table. After every upgrade please run the following generator:

    $ rails g acts_as_audited:upgrade

The upgrade generator will only generate migrations that are missing, or no migrations at all if you are up to date.

== Usage

Declare +acts_as_audited+ on your models:

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

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

To record an audit for an associated model, use the <tt>:associated_with</tt> option.

    class User < ActiveRecord::Base
      acts_as_audited :associated_with => :company
    end

If desired, the associated model can access its audits using <tt>has_associated_audits</tt>.

    class Company < ActiveRecord::Base
      has_many :users
      has_associated_audits
    end

To record a user in the audits outside of a web request, you can use +as_user+:

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

== Caveats

If your model declares +attr_accessible+ after +acts_as_audited+, you need to set <tt>:protect</tt> 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
  end

== Compatability
{'fraction_non_alphanumeric': 0.06450437317784256, 'fraction_numerical': 0.002551020408163265, 'mean_word_length': 4.397246804326451, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 40, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2697109', 'n_tokens_mistral': 1657, 'n_tokens_neox': 1562, 'n_words': 690}