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 2.0.0 works now for Rails 4.0 with Ruby 1.9.3 and 2.0.0. Use the version 1.0.2 for Rails ~3.0 with Ruby 1.8.7 or higher.
The migration helpers changed. The column statement is now named
t.authorstamps instead of
t.authors. Similar the
changing a table is named
add_authorstamp. The columns
generated are still named the same - so they are calles
Add below to your Gemfile and run the
In a models migration add:
This will add columns
:string to your model.
In case you want to use another type, simply pass the type as argument, e.g.
By default the columns are mandatory (
:null => false). 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
false if required. Note: If you pass options you
have to pass the type as well - sample migration statments:
(:your_table_name, :string, :null => true)
change_table :your_table_name do |t| t.(:integer, :null => true) end
The authorstamps methods are simple conveniance methods (as
regular timestamp methods are). You can simply add columns named
updated_by using regular migration
statements.<p/> You can name the attributes
updated_by_id. If these columns
are detected they are filled as well.
All you need to do is to set the current author such as e.g:
update then will set
the respetive attributes
updated_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
Concern::Audit::Author stores the
author in a Thread-Local variable.
In case you need associations to a respective Author Model you have to set them up yourselfs.
Works for Rails4 with Ruby1.9.3 and Ruby 2.0.0
Works now not only for
updated_by, but as well for attributes
Fixed migrations so option can be passed