Userstamp plugin
Plugin details
Documentation
ruby script/plugin install svn://delynnberry.com/code/plugins/userstamp/trunk
Here is a simple example for how to use the Userstamp plugin. First, create 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 create a belongs_to relationship. For example:
class Post < ActiveRecord::Base belongs_to :created_by, :class_name => "User", :foreign_key => "created_by" belongs_to :updated_by, :class_name => "User", :foreign_key => "updated_by" end
Then in your ApplicationController create a before_filter to automatically set the current_user:
class ApplicationController < ActionController::Base before_filter do |c| User.current_user = User.find(c.session[:user].id) unless c.session[:user].nil? end end
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". You'll 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 the Userstamp plugin directory:
ruby userstamp_test.rb
Credits and Special Thanks
--------------------------
The original idea for this plugin came from the Rails Wiki article entitled "Extending ActiveRecord" (http://wiki.rubyonrails.com/rails/pages/ExtendingActiveRecordExample).
Special Thanks to Ben Reubenstein for helping me stress test this plugin.
Further Documentation
There is currently no advanced documentation for this plugin.
New documentationEdit plugin | (0 older versions) | Last edited by: scott, 9 months ago

