Plugins - Userstamp

StarAdd to favorites

The Userstamp Plugin extends ActiveRecord::Base to add automatic updating of createdby and updatedby attributes of your models in much the same way that the ActiveRecord::Timestamp module updates created(at/on) and updated(at/on) attributes.

The module requires that your application’s user object (User by default) contains an accessor called currentuser be set with an instance of the currently logged in user (typically using a beforefilter. This module can also be turned off on a case by case basis by setting the record_userstamps attribute of your ActiveRecord object to false.

Delynn Berry

http://delynnberry.com/projects/userstamp

svn://delynnberry.com/code/plugins/userstamp/trunk

OpenSource

  • Currently 4.7/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Model

Tags

Comments

Add a comment
axs89 25 Jun 2008

When I try to install, it does not seem to work, all i get is one line of feedback:

> ruby script\plugin install git://github.com/delynn/user stamp.git removing: C:/dev/XXX/YYY/vendor/plugins/userstamp/.git

ctran 10 Mar 2008

Made some changes to work with Rails 2.0.2 at http://github.com/ctran/annotate_models

Peer Allan 12 Jul 2007

I am trying to use this plugin but the repository is asking for a username and password. Is there an anonymous login or is this just an error?

pireland 4 Jun 2007

make sure to define the foreign key in your user.rb

ex:
hasmany :posts, :foreignkey => "created_by"

anders 18 May 2007

The solution below does not work for me.

pireland 6 May 2007

The one below worked well for me

The original plugin gave me a stack error so I removed it.

Björn 11 Apr 2007

I had difficulties with userstamp plugin in combination with a custom before_filter. After thinking about other ways to achieve what the plugin does, I found a very simple solution:

In your environment.rb put

set createdby and updatedby on create and update

class ActiveRecord::Base before_update UserStamp.new before_create UserStamp.new end

and then add a file UserStamp.rb into app/models, containing

class UserStamp def before_update(model) if nil != User.currentuser && model.respondto?(:updated_by) model.updatedby = User.currentuser end end

def before_create(model) if nil != User.currentuser && model.respondto?(:created_by) model.createdby = User.currentuser end end end

Same prerequisites as for the plugin: you need to have User.currentuser set to a user, have the belongsto set in your models and should have fields called createdby and updatedby.

That's it - and thanks to Delynn for providing the original idea.

Search Plugins

Query syntax

Plugins by Category

Sponsors

Rails Kits: Get Code. Get Moving.

Have a comment?