= ar-audit-tracer
{}[http://travis-ci.org/verticonaut/ar-audit-tracer]
== Summary
ar-audit-tracer patches ActiveRecord so modifiers of a record can be traked on saving (insert/update).
It works exactly like 'timestamps' (see usage below).
The new version 1.0.2 works now for Rails 3.0, 3.1 and 3.2 and is tested with Ruby 1.8.7, 1.9.2 and 1.9.3.
== Installation
Add below to your Gemfile and run the +bundle+ command
gem 'ar-audit-tracer'
== Usage
=== Migration
In a models migration add:
t.authors
This will add columns +created_by+ and +updated_by+ of type +:string+ to your model.
In case you want to use another type, simply pass the type as argument, e.g.
t.authors(:integer)
By default the columns are mandatory (:null => true). If you have existing models you want to change
you have to pass the option :null => true, update the values in the new attributes columns and add another
migration to change the column to :null => false if required.
Note: If you pass options you have to pass the type as well - sample migration statments:
add_authors(:your_table_name, :string, :null => true)
or
change_table :your_table_name do |t|
t.authors(:integer, :null => true)
end
==== Note
The _authors_ methods are simple conveniance methods (as regular timestamp methods are). You can simply
add columns named +created_by+ and +updated_by+ using regular migration statements.
=== Configuration
All you need to do is to set the current author such as e.g:
Concern::Audit::Author.current="bad_man"
Each ActiveRecord +save+ or +update+ then will set the respetive attributes +created_by+ and +modified_by+ automatically, whereas the modifier is set to the same value as the creator on model creation.
In a Rails Application you would set the author as described above in a +before_filter+.
Concern::Audit::Author stores the author in a Thread-Local variable.
== Additional Notes
In case you need associations to a respective Author Model you have to set them up yourselfs.
== Changelog
=== Version 1.0.2
* Fixed migrations so option can be passed