Plugins - Userstamp
Add to favoritesThe 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.
http://delynnberry.com/projects/userstamp
svn://delynnberry.com/code/plugins/userstamp/trunk
OpenSource
Model

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
Made some changes to work with Rails 2.0.2 at http://github.com/ctran/annotate_models
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?
make sure to define the foreign key in your user.rb
ex:
hasmany :posts, :foreignkey => "created_by"
The solution below does not work for me.
The one below worked well for me
The original plugin gave me a stack error so I removed it.
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.