infused / blame

Blame is a simple alternative to the userstamp plugin for Rails, which adds userstamps to ActiveRecord models

This URL has Read+Write access

blame / README.rdoc
100644 47 lines (30 sloc) 1.56 kb

Blame

Automatically userstamps create and update operations if the table has columns named created_by and/or updated_by. The Blame plugin attempts to mirror the simplicity of ActiveRecord’s timestamp module.

Blame assumes that you are using restful-authentication and expects User.current_user to return the current user. You can override this behavior by writing your own userstamp_object method in ActiveRecord::Base or any of your models. For example:

  def userstamp_object
    User.find(session[:user_id])
  end

If you don’t like created_by/updated_by you can customize the column names:

  # Globally in environment.rb
  ActiveRecord::Base.created_userstamp_column = :creator_id

  # In a model definition
  class Subscription
    self.created_userstamp_column = :creator_id
    self.updated_userstamp_column = :updater_id
  end

Automatic userstamping can be turned off globally by setting:

  ActiveRecord::Base.record_userstamps = false

Blame adds a userstamps migration helper which will add the created_by and updated_by columns (or your custom column names) to your table:

  create_table :widgets do |t|
    t.string :name
    t.timestamps
    t.userstamps
  end

Installation

  ruby script/plugin install git://github.com/infused/blame.git

Credit

Thanks to DeLynn Berry <delynn@gmail.com> for writing the original Userstamp plugin (github.com/delynn/userstamp/tree/master), which is the inspiration for this plugin.

Copyright © 2008-2009 Keith Morrison <keithm@infused.org>, released under the MIT license