I’m pleased to announce a new plugin for Rails: Userstamp. You can read
blog post at
and/or read all about it at the perminant page
http://www.delynnberry.com/pages/userstamp. Any comments or suggestions
improvement are much appreciated.
A dump of the Readme file is contained below
Userstamp Plugin (v 1.0)
The Userstamp Plugin extends ActiveRecord::Base(
http://api.rubyonrails.com/classes/ActiveRecord/Base.html) to add
updating of created_by and updated_by attributes of your models in much
same way that the ActiveRecord::Timestamp(
updates created_(at/on) and updated_(at/on) attributes.
The module requires that your application’s user object (User by
contains an accessor called current_user be set with an instance of the
currently logged in user (typically using a before_filter(
This module can also be turned off on a case by case basis by setting
record_userstamps attribute of your ActiveRecord object to false.
To install the Userstamp plugin into a current Rails application run the
script/plugin script from the root of your application passing it the
Once installed you will need to restart your webserver for the plugin to
loaded into the Rails environment.
Here is a simple example for how to use the Userstamp plugin. First,
a User model object (either using the generator or manually creating the
file). Adjust your model to include the current_user accessor like so:
class User < ActiveRecord::Base cattr_accessor :current_user end
Second, create another table and model that will use the Userstamp
functionality (I’m using Post for this example). Be sure to add the
created_by and updated_by columns to your table definition and also
belongs_to relationship. For example:
class Post < ActiveRecord::Base belongs_to :created_by, :class_name => "User", :foreign_key =>
belongs_to :updated_by, :class_name => “User”, :foreign_key =>
Then in your ApplicationController create a before_filter to
set the current_user:
class ApplicationController < ActionController::Base before_filter do |c| User.current_user = User.find(c.session[:user].id) unless
Uninstalling is simply a matter of running script/plugin from the root
your Rails application. Except this time you pass the uninstall
script/plugin unistall userstamp
RDoc has been run on the plugin directory and is available in the
Running Unit Tests
There are extensive unit tests in the “test” directory of the plugin.
Currently, only MySQL is supported, but
you should be able to easily fix this by looking at “connection.rb”.
need to create a
database for the tests and put the connection information into "
connection.rb" as well as import the schema file
for MySQL that can be found at “test/fixtures/mysql.sql”.
To run the test simply execute the follow from the test directory inside
Userstamp plugin directory:
Bugs & Feedback
Bug reports and feedback are always welcome. Please send them to
[email protected] with [Userstamp] in the subject line.
You can also visit (
and post a comment on any of the posts.
Credits and Special Thanks