<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>infused.org &#187; plugin</title>
	<atom:link href="http://www.infused.org/category/ruby-on-rails/plugin/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.infused.org</link>
	<description></description>
	<lastBuildDate>Tue, 05 Jan 2010 00:33:31 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>The Blame Game</title>
		<link>http://www.infused.org/2009/01/05/the-blame-game/</link>
		<comments>http://www.infused.org/2009/01/05/the-blame-game/#comments</comments>
		<pubDate>Tue, 06 Jan 2009 00:20:07 +0000</pubDate>
		<dc:creator>Keith</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://www.infused.org/?p=440</guid>
		<description><![CDATA[In just about every Rails project I&#8217;ve worked on over the last several years we&#8217;ve needed track the user who creates and updates database records.  The most popular solution seems to be DeLynn Berry&#8217;s userstamp plugin and, until recently, that&#8217;s what we&#8217;ve always chosen to use too.  But after fighting incompatibility with newer [...]]]></description>
			<content:encoded><![CDATA[<p>In just about every Rails project I&#8217;ve worked on over the last several years we&#8217;ve needed track the user who creates and updates database records.  The most popular solution seems to be DeLynn Berry&#8217;s userstamp plugin and, until recently, that&#8217;s what we&#8217;ve always chosen to use too.  But after fighting incompatibility with newer versions of Rails I decided to write my own plugin.  Enter <a href="http://github.com/infused/blame/tree/master">Blame</a>.</p>
<p>Blame automatically userstamps create and update operations if the table has columns named created_by and/or updated_by.</p>
<p><b>Installation:</b></p>
<pre><code>ruby script/plugin install git://github.com/infused/blame.git</code></pre>
<p>Blame assumes that you are using <a href="http://github.com/technoweenie/restful-authentication/tree/master">restful-authentication</a> and expects User.current_user to return the current user. You can override this behavior by overriding the default userstamp_object method in ActiveRecord::Base or in any of your models. For example, maybe you just want to find the current user bases on the a session variable:</p>
<pre><code># In environment.rb
class ActiveRecord::Base
  def userstamp_object
    User.find(session[:user_id])
  end
end
</code></pre>
<p>Maybe you don’t like the default column names of created_by/updated_by. You can customize the column names globally or for individual models:</p>
<pre><code># Globally in environment.rb
ActiveRecord::Base.created_userstamp_column = :creator_id

# In a model definition
class Subscription
  self.created_userstamp_column = :creator_id
  self.updated_userstamp_column = :updater_id
end
</code></pre>
<p>Automatic userstamping can be turned off by setting record_userstamps:</p>
<pre><code># Globally in environment.rb
ActiveRecord::Base.record_userstamps = false

# In a model definition
class Subscription
  self.record_userstamps = false
end

</code></pre>
<p>Blame also adds a migration helper which will add the created_by and updated_by columns (or your custom column names) to your table:</p>
<pre><code>create_table :widgets do |t|
  t.string :name
  t.timestamps
  t.userstamps
end
</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.infused.org/2009/01/05/the-blame-game/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
