Sha256: 0062b2c5b9d9e1b83dc67f946990d1c71ec00644eb3ceada408e1859c3aab98f

Contents?: true

Size: 1.58 KB

Versions: 2

Compression:

Stored size: 1.58 KB

Contents

= track_changes

TrackChanges is a Rails plugin to facilitate tracking
changes made to an ActiveRecord model in your
Controller actions.

== Why?

I originally looked at the available auditing solutions
and it appeared that most of them were not thread-safe.

== 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]

    # 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"
      end
    end

    # Normal controller actions
    # ...

    protected

    def get_post
      @post = Post.find(params[:id])
    end
  end


== COPYRIGHT

Copyright (c) 2008-2010 Matt Haley. See LICENSE for details.

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
track_changes-0.4.1 README.rdoc
track_changes-0.4.0 README.rdoc