README.rdoc in track_changes-0.3.2 vs README.rdoc in track_changes-0.4.0

- old
+ new

@@ -1,30 +1,58 @@ = track_changes TrackChanges is a Rails plugin to facilitate tracking changes made to an ActiveRecord model in your -Controller#update actions. By default, the block is -only called if the changes hash is not empty. +Controller actions. -A TrackChanges::Filter is instantiated on each run of the <tt>before_filter</tt> -so it should be thread-safe. +== Why? -Consult the generated rdoc for more information. +I originally looked at the available auditing solutions +and it appeared that most of them were not thread-safe. -== Example +== Installation + gem install track_changes + +== Configuration + +You need to have an Audit class that has a polymorphic +<tt>belongs_to</tt> association to <tt>:audited</tt>. In +addition, the Audit model must have a <tt>user</tt> +attribute, and your controllers must respond to +<tt>current_user</tt>. + +Example Audit class: + + class Audit < ActiveRecord::Base + belongs_to :audited, :polymorphic => true + serialize :change_set + end + +Example Audited class: + + class Post < ActiveRecord::Base + has_many :audits, :as => :audited + end + +== Controller Example + +In this example, after the `update` action is called, +the `@post` will be compared to a previous version, and +if there are any changes, an audit will be created. + class PostController < ApplicationController include TrackChanges before_filter :get_post, :except => [:index, :new] - track_changes_to :post do |r| - # r.changes => Model#changes made during update action - RAILS_DEFAULT_LOGGER.debug(r.changes.inspect) - end + # specify a single model + track_changes :post - + # you can also specify multiple models + #track_changes :post1, :post2, ... + def update if @post.update_attributes(params[:post]) flash[:notice] = "Success." else render :action => "edit" @@ -42,6 +70,6 @@ end == COPYRIGHT -Copyright (c) 2008 Matt Haley. See LICENSE for details. +Copyright (c) 2008-2010 Matt Haley. See LICENSE for details.