プラグイン名
Userstamp
このプラグインができること
- created_atやupdated_atのノリで、誰が登録したか、更新したかを記録するcreated_byとupdated_byを自動記録する。
- created_byやupdated_byで記録されるのは、関連づけられたモデルのIDで、Acts_as_Authenticatedと相性が良い。(他もいける)
対象バージョン
1.2系
インストール方法
- script/pluginでsubversionリポジトリを指定
ちょー簡単な使い方
script/plugin install svn://delynnberry.com/code/plugins/userstamp/trunk
でインストールして、ユーザ情報が保存されているモデルに
class User < ActiveRecord::Base
cattr_accessor :current_user
end
を仕込み、created_byやupdated_byを仕込みたいモデルに
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
を仕込んで、最後に格納すべきユーザID(この場合、user.id)をアプリケーションコントローラーなどに
class ApplicationController < ActionController::Base
before_filter do |c|
User.current_user = User.find(c.session[:user].id) unless c.session[:user].nil?
end
end
みたいな形で格納しておく。
ちなみに、Acts_as_Authenticatedを使うなら、こんな感じ。
before_filter do |c|
User.current_user = User.find(c.session[:user]) unless c.session[:user].nil?
end
※idを省いただけ
これだけでUserstampが使える。
公式ページ
日本語解説ページ
外国語解説ページ
- 今のところ必要ないかも(このページで情報が足りるのでは?)
コメント
最終更新:2008年01月05日 09:12