<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.0.1" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
	<title>Comments on: Rails - Auto Assign Created By and Updated By</title>
	<link>http://www.pluitsolutions.com/2006/08/15/rails-auto-assign-created-by-and-updated-by/</link>
	<description>Web Developer, Web Designer, Ruby on Rails Developer, a Curious Man based in Singapore</description>
	<pubDate>Fri, 10 Feb 2012 12:47:44 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.0.1</generator>

	<item>
		<title>by: Brian Candler</title>
		<link>http://www.pluitsolutions.com/2006/08/15/rails-auto-assign-created-by-and-updated-by/#comment-182860</link>
		<pubDate>Fri, 08 Jan 2010 16:13:28 +0000</pubDate>
		<guid>http://www.pluitsolutions.com/2006/08/15/rails-auto-assign-created-by-and-updated-by/#comment-182860</guid>
					<description>Using a thread-local variable is best, since Rails apps *can* now be run multi-threaded (config.threadsafe!)

A thread-local variable is already used to set Time.zone and have it propagate to the model: see activesupport-2.3.4/lib/active_support/core_ext/time/zones.rb

There are other cases where I'd like the model to interact with the request. For example, on update I'd like to log the IP address of the user (request.ip). Or when doing bulk updates, I'd like them all to have an identical updated_at time; that means taking a 'snapshot' of the current time for this particular request.

Using thread-local variables works, but somehow it doesn't feel like a particularly clean way to make the model interact with the request. The logical conclusion would be to set Thread.current['session'] = session, Thread.current['request'] = request etc, which is probably going too far.

You also have to be sure that you reset these variables on every request, of course.</description>
		<content:encoded><![CDATA[<p>Using a thread-local variable is best, since Rails apps *can* now be run multi-threaded (config.threadsafe!)</p>
<p>A thread-local variable is already used to set Time.zone and have it propagate to the model: see activesupport-2.3.4/lib/active_support/core_ext/time/zones.rb</p>
<p>There are other cases where I&#8217;d like the model to interact with the request. For example, on update I&#8217;d like to log the IP address of the user (request.ip). Or when doing bulk updates, I&#8217;d like them all to have an identical updated_at time; that means taking a &#8217;snapshot&#8217; of the current time for this particular request.</p>
<p>Using thread-local variables works, but somehow it doesn&#8217;t feel like a particularly clean way to make the model interact with the request. The logical conclusion would be to set Thread.current[&#8217;session&#8217;] = session, Thread.current[&#8217;request&#8217;] = request etc, which is probably going too far.</p>
<p>You also have to be sure that you reset these variables on every request, of course.
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Herryanto Siatono</title>
		<link>http://www.pluitsolutions.com/2006/08/15/rails-auto-assign-created-by-and-updated-by/#comment-90961</link>
		<pubDate>Thu, 07 Aug 2008 05:56:19 +0000</pubDate>
		<guid>http://www.pluitsolutions.com/2006/08/15/rails-auto-assign-created-by-and-updated-by/#comment-90961</guid>
					<description>Chris the !user.nil? for created_by has been checked earlier, while created_by.nil? check is not to auto-assign, if it has been manually assign.</description>
		<content:encoded><![CDATA[<p>Chris the !user.nil? for created_by has been checked earlier, while created_by.nil? check is not to auto-assign, if it has been manually assign.
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Chris</title>
		<link>http://www.pluitsolutions.com/2006/08/15/rails-auto-assign-created-by-and-updated-by/#comment-90823</link>
		<pubDate>Wed, 06 Aug 2008 11:32:52 +0000</pubDate>
		<guid>http://www.pluitsolutions.com/2006/08/15/rails-auto-assign-created-by-and-updated-by/#comment-90823</guid>
					<description>I think I may have found the issue.  It must be difference between MySQL on Windows and MySQL on my Linux server... My created_by field is set to be not null with a default value of 0.  On Windows usermonitor works fine and updates both the created_by and updated_by fields.  But, when it is executing on Linux it seems like created_by already has the default value of 0 and it fails the condition &quot;&amp;#38;&amp;#38; created_by.nil?&quot;.  Shouldn't this condition be &quot; &amp;#38;&amp;#38; !user.nil?&quot; just like it is in the update_with_user method?</description>
		<content:encoded><![CDATA[<p>I think I may have found the issue.  It must be difference between MySQL on Windows and MySQL on my Linux server&#8230; My created_by field is set to be not null with a default value of 0.  On Windows usermonitor works fine and updates both the created_by and updated_by fields.  But, when it is executing on Linux it seems like created_by already has the default value of 0 and it fails the condition &#8220;&amp;&amp; created_by.nil?&#8221;.  Shouldn&#8217;t this condition be &#8221; &amp;&amp; !user.nil?&#8221; just like it is in the update_with_user method?
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Herryanto Siatono</title>
		<link>http://www.pluitsolutions.com/2006/08/15/rails-auto-assign-created-by-and-updated-by/#comment-90772</link>
		<pubDate>Wed, 06 Aug 2008 05:12:45 +0000</pubDate>
		<guid>http://www.pluitsolutions.com/2006/08/15/rails-auto-assign-created-by-and-updated-by/#comment-90772</guid>
					<description>@Chris, I didn't encounter such problem before, you probably have to track ruby-debug with  or println some comments to track what's going on.</description>
		<content:encoded><![CDATA[<p>@Chris, I didn&#8217;t encounter such problem before, you probably have to track ruby-debug with  or println some comments to track what&#8217;s going on.
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Chris</title>
		<link>http://www.pluitsolutions.com/2006/08/15/rails-auto-assign-created-by-and-updated-by/#comment-90599</link>
		<pubDate>Tue, 05 Aug 2008 02:57:03 +0000</pubDate>
		<guid>http://www.pluitsolutions.com/2006/08/15/rails-auto-assign-created-by-and-updated-by/#comment-90599</guid>
					<description>I have installed this and it is working perfectly on my development computer.  However, I have pushed it out to my test server and it is only updating &quot;updated_by&quot; and not &quot;created_by&quot;.  Any ideas on what the problem could be?</description>
		<content:encoded><![CDATA[<p>I have installed this and it is working perfectly on my development computer.  However, I have pushed it out to my test server and it is only updating &#8220;updated_by&#8221; and not &#8220;created_by&#8221;.  Any ideas on what the problem could be?
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Herryanto Siatono</title>
		<link>http://www.pluitsolutions.com/2006/08/15/rails-auto-assign-created-by-and-updated-by/#comment-37061</link>
		<pubDate>Wed, 15 Aug 2007 01:29:37 +0000</pubDate>
		<guid>http://www.pluitsolutions.com/2006/08/15/rails-auto-assign-created-by-and-updated-by/#comment-37061</guid>
					<description>@Daryl, there's no thread safety issue, yep it's okay to use. Yeah I would say no impact. I've been using it since day one, no issue at all.</description>
		<content:encoded><![CDATA[<p>@Daryl, there&#8217;s no thread safety issue, yep it&#8217;s okay to use. Yeah I would say no impact. I&#8217;ve been using it since day one, no issue at all.
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Daryl</title>
		<link>http://www.pluitsolutions.com/2006/08/15/rails-auto-assign-created-by-and-updated-by/#comment-37055</link>
		<pubDate>Tue, 14 Aug 2007 23:38:54 +0000</pubDate>
		<guid>http://www.pluitsolutions.com/2006/08/15/rails-auto-assign-created-by-and-updated-by/#comment-37055</guid>
					<description>Despite your thread safety, is this method still okay to use?
Is it overkill or is there no impact over the traditional method?
Do you still use this method? =)</description>
		<content:encoded><![CDATA[<p>Despite your thread safety, is this method still okay to use?<br />
Is it overkill or is there no impact over the traditional method?<br />
Do you still use this method? =)
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Herryanto Siatono</title>
		<link>http://www.pluitsolutions.com/2006/08/15/rails-auto-assign-created-by-and-updated-by/#comment-24803</link>
		<pubDate>Sat, 14 Apr 2007 01:52:34 +0000</pubDate>
		<guid>http://www.pluitsolutions.com/2006/08/15/rails-auto-assign-created-by-and-updated-by/#comment-24803</guid>
					<description>@Platte Daddy, yeah I realized that after I delve more into rails, was a newbie back then. Thanks for the update. I've put up a note in my post.</description>
		<content:encoded><![CDATA[<p>@Platte Daddy, yeah I realized that after I delve more into rails, was a newbie back then. Thanks for the update. I&#8217;ve put up a note in my post.
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Platte Daddy</title>
		<link>http://www.pluitsolutions.com/2006/08/15/rails-auto-assign-created-by-and-updated-by/#comment-24781</link>
		<pubDate>Fri, 13 Apr 2007 18:41:24 +0000</pubDate>
		<guid>http://www.pluitsolutions.com/2006/08/15/rails-auto-assign-created-by-and-updated-by/#comment-24781</guid>
					<description>Did you know that Rails keeps each request isolated? It's built on a CGI model that chucks everything after each request. You don't have to worry about thread safety per request.

The only time you would need to worry about thread safety in Rails is if you're working with threaded code of your own.</description>
		<content:encoded><![CDATA[<p>Did you know that Rails keeps each request isolated? It&#8217;s built on a CGI model that chucks everything after each request. You don&#8217;t have to worry about thread safety per request.</p>
<p>The only time you would need to worry about thread safety in Rails is if you&#8217;re working with threaded code of your own.
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Herryanto Siatono</title>
		<link>http://www.pluitsolutions.com/2006/08/15/rails-auto-assign-created-by-and-updated-by/#comment-8460</link>
		<pubDate>Fri, 22 Dec 2006 18:29:01 +0000</pubDate>
		<guid>http://www.pluitsolutions.com/2006/08/15/rails-auto-assign-created-by-and-updated-by/#comment-8460</guid>
					<description>It really depends, Vidal, feel free some people just store id in session[:user] while some store the user object. 

Feel free to tweak the codes around to meet your needs. :)</description>
		<content:encoded><![CDATA[<p>It really depends, Vidal, feel free some people just store id in session[:user] while some store the user object. </p>
<p>Feel free to tweak the codes around to meet your needs. :)
</p>
]]></content:encoded>
				</item>
</channel>
</rss>

