<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Workin' on it. &#187; rails</title>
	<atom:link href="http://jameshalberg.wordpress.com/category/rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://jameshalberg.wordpress.com</link>
	<description></description>
	<lastBuildDate>Sat, 19 Nov 2011 14:15:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='jameshalberg.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Workin' on it. &#187; rails</title>
		<link>http://jameshalberg.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://jameshalberg.wordpress.com/osd.xml" title="Workin&#039; on it." />
	<atom:link rel='hub' href='http://jameshalberg.wordpress.com/?pushpress=hub'/>
		<item>
		<title>MySQL Triggers w/Rails</title>
		<link>http://jameshalberg.wordpress.com/2010/02/28/mysql-triggers-wrails/</link>
		<comments>http://jameshalberg.wordpress.com/2010/02/28/mysql-triggers-wrails/#comments</comments>
		<pubDate>Mon, 01 Mar 2010 02:54:24 +0000</pubDate>
		<dc:creator>Jim</dc:creator>
				<category><![CDATA[deployment]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Test Driven Development (TDD)]]></category>
		<category><![CDATA[triggers]]></category>

		<guid isPermaLink="false">http://jameshalberg.com/?p=391</guid>
		<description><![CDATA[I recently incorporated db-triggers with a Rails app to maintain some counts that were otherwise fairly expensive to retrieve.  Rails wasn&#8217;t super-pumped about the idea (what with the &#8220;keep all the logic in the app&#8221; approach and all), but sometimes&#8230; you &#8230; <a href="http://jameshalberg.wordpress.com/2010/02/28/mysql-triggers-wrails/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jameshalberg.wordpress.com&amp;blog=160606&amp;post=391&amp;subd=jameshalberg&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I recently incorporated db-triggers with a Rails app to maintain some counts that were otherwise fairly expensive to retrieve.  Rails wasn&#8217;t super-pumped about the idea (what with the &#8220;keep all the logic in the app&#8221; approach and all), but sometimes&#8230; you know&#8230; you know better than your framework.</p>
<p>Some things I was aiming for:</p>
<ol>
<li>Set them up with normal migrations.</li>
<li>Test them with the normal test suite/normal fixtures.</li>
<li>Make recovery/reset simple for when the table (inevitably) is somehow out of sync.</li>
</ol>
<p><strong>The &#8220;frequent counts&#8221; table</strong></p>
<p>I&#8217;ll have multiple counts but not TOO many &#8212; enough that I don&#8217;t want to have a column per count but not enough that I mind using &#8220;LIKE&#8221; to lookup patterns, so my table has: id, code, current_count.</p>
<p>Code will be a unique key (important later) and be formatted like &#8220;style_ABC_size_456&#8243;.</p>
<p>So, when a new item is added it&#8217;ll be associated with a style and some sizes &#8211; each combination will either need to be setup (with a current_count = 1) or an existing combo will be found and +=1.</p>
<p>The FrequentCount class has the fairly straightforward finders that you&#8217;d expect + methods to reset each of the counts that it contains.  The reset methods follow the pattern &#8220;reset_frequent_count_COUNT_NAME&#8221; -&gt; they clear the existing counts that they maintain before repopulating them.</p>
<p>I also threw in a reset_all method that looks for anything on the class following the &#8220;reset_frequent_count_COUNT_NAME&#8221; pattern and runs them.</p>
<p><strong>The trigger-SQL</strong></p>
<p>The SQL for creating the triggers will be needed by the migration as well as the test suite.  In fact, the test suite will need to run them somewhat often due to the way the standard tests &#8221;prepare&#8221; the database.</p>
<p>I ended up throwing it in lib/trigger_sql.rb.  Methods there are named with the pattern &#8220;sql_for_TABLE_OPERATION_TRIGGER_NAME&#8221; ex: sql_for_items_insert_style_and_size</p>
<div id="_mcePaste">Many of the triggers could not rely on pre-existing rows.  i.e. a new style/size combination needs to INSERT where an existing combo could update ( +=1 ).  To get around this, I relied on the unique key setup earlier on the &#8220;code&#8221; field for the frequent counts table.  &lt;&#8211; that allowed me to lean on insert statements with &#8220;ON DUPLICATE KEY&#8221; clauses with update statements.  Something like this&#8230;</div>
<blockquote style="margin:25px 0;">
<div>create trigger items_insert_style_and_size after insert on items<br />
for each row<br />
begin<br />
insert into frequent_counts(code, current_count)<br />
values (concat(&#8216;style_&#8217;, new.style, &#8216;_size_&#8217;, new.size), 1)<br />
on duplicate key update current_count = current_count + 1;<br />
end;</div>
</blockquote>
<div><strong><span style="font-weight:normal;"><strong>The Migration</strong></p>
<div id="_mcePaste">I&#8217;ve already given away most of the fun stuff about the migration.  It just needs to run through the triggers that are being setup at this specific time, doing things like:</div>
<blockquote style='margin:25px 0;'>
<div>TriggerSql.connection.execute(TriggerSql.sql_for_items_insert_items_by_style_and_size)</div>
</blockquote>
<div>and then make sure to populate it all (with that reset_all) method when we&#8217;re done. &lt;&#8211; next time out I may want to call specific methods to reset just the ones I care about but this first time, I can just do the whole table.</div>
<div></div>
<p></span></strong></div>
<div><strong>Testing with Fixtures</strong></div>
<div>Rails goes a little too far when running the default test tasks for us &#8211; it ends up nuking the triggers on us, but not to fear: it&#8217;s a quick hack in the Rakefile.</div>
<div></div>
<div>I&#8217;m going to spare you some details (drop me a line if you want them) but I basically overrode the db:test:prepare method to call a special version of the clone_structure task.  My version has a dependent task that does:</div>
<blockquote style='margin:25px 0;'>
<div>
<div># find methods that follow our pattern of &#8220;methods providing trigger sql&#8221; and execute the contents of each</div>
<div>TriggerSql.methods.select{ |m| m =~ /sql_for_.+/ }.each do |method_name|</div>
<div>ActiveRecord::Base.connection.execute(TriggerSql.send(method_name))</div>
<div>end</div>
</div>
</blockquote>
<div>As you see there, it&#8217;s leaning on that naming convention &#8220;sql_for_TABLE_OPERATION_TRIGGER_NAME&#8221; to find the sql to (re)apply.</div>
<div></div>
<div style='margin-top:10px;'><strong>That&#8217;s it!</strong></div>
<div>Migrations set them up and share the code to do so with the fixtures that can repeat the tests whenever we need.  Those reset methods also come in handy not only for the initial population (by the migration) but we can call them manually should we need them.</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jameshalberg.wordpress.com/391/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jameshalberg.wordpress.com/391/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jameshalberg.wordpress.com/391/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jameshalberg.wordpress.com/391/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jameshalberg.wordpress.com/391/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jameshalberg.wordpress.com/391/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jameshalberg.wordpress.com/391/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jameshalberg.wordpress.com/391/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jameshalberg.wordpress.com/391/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jameshalberg.wordpress.com/391/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jameshalberg.wordpress.com/391/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jameshalberg.wordpress.com/391/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jameshalberg.wordpress.com/391/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jameshalberg.wordpress.com/391/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jameshalberg.wordpress.com&amp;blog=160606&amp;post=391&amp;subd=jameshalberg&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jameshalberg.wordpress.com/2010/02/28/mysql-triggers-wrails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">jameshalberg</media:title>
		</media:content>
	</item>
		<item>
		<title>Friend&#8217;s Price</title>
		<link>http://jameshalberg.wordpress.com/2009/11/25/friends-price/</link>
		<comments>http://jameshalberg.wordpress.com/2009/11/25/friends-price/#comments</comments>
		<pubDate>Wed, 25 Nov 2009 06:56:18 +0000</pubDate>
		<dc:creator>Jim</dc:creator>
				<category><![CDATA[rails]]></category>
		<category><![CDATA[Recommended Sites]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[heroku]]></category>

		<guid isPermaLink="false">http://jameshalberg.com/?p=377</guid>
		<description><![CDATA[A friend was asking the other day about getting a little site up and running for his small business.  Seems like the scope is going to be quite small (famous last words) and there are a few things I&#8217;ve been &#8230; <a href="http://jameshalberg.wordpress.com/2009/11/25/friends-price/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jameshalberg.wordpress.com&amp;blog=160606&amp;post=377&amp;subd=jameshalberg&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>A friend was asking the other day about getting a little site up and running for his small business.  Seems like the scope is going to be quite small (famous last words) and there are a few things I&#8217;ve been meaning to checkout lately, so I think I&#8217;m going to give it a stab.</p>
<p>Night one went something like this:</p>
<p>I got an invite (did they do invites?) to checkout <a href="http://heroku.com/">Heroku</a> really early on.  At the time, I remember devoting a night to it &#8211; working with an online editor (or maybe I was ssh&#8217;d in with vi or something?) and basically just getting a little &#8220;Hello World&#8221; up and running.  Ever since bumping into <a href="http://www.writebetterbits.com/2009/10/picture-downloader-small-study-in.html">Jim Fiorato&#8217;s app/case study</a> the other day, I&#8217;ve been meaning to revisit a bit.</p>
<p>It&#8217;s entirely likely that the friend&#8217;s site will actually not need anything but static HTML, but hey: I can always tune the caching and free hosting can&#8217;t be argued with, right?</p>
<p>So, I opened an account out at herku.com and grabbed the heroku gem; installed git (officially taking me off the short list of people that still hadn&#8217;t given it a chance) and set to work on getting my app out there.</p>
<p>I hadn&#8217;t written anything, so I was just wanting to throw the &#8220;welcome to Rails&#8221; app out there to make sure everything was setup correctly.  The first bump was some fun with SSH keys.  I&#8217;m actually still not sure exactly what the issue was but there seemed to be some commands that were respecting the path to the key that I had setup but some others that seemed to be looking in the default location (~/.ssh).  I am actually thinking now that I probably could have got around it with a little more effort put into the config but I ended up just using the default key location &#8212; no probs after that.</p>
<p>At that point + some very simple/standard Rails app config, it was incredibly early to push the app out there, setup a few tables (via migrations) and get to work.</p>
<p>A little effort into a pretty basic layout and we&#8217;re underway.  It&#8217;s nothing spectacular to checkout at the moment &#8211; generic copy, placeholder colors/blocks and text&#8230; but someday it&#8217;ll be a star.</p>
<p style="text-align:center;"><a href="http://jameshalberg.files.wordpress.com/2009/11/firstpass.png"><img class="aligncenter size-full wp-image-384" title="firstpass" src="http://jameshalberg.files.wordpress.com/2009/11/firstpass.png?w=500&#038;h=299" alt="" width="500" height="299" /></a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jameshalberg.wordpress.com/377/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jameshalberg.wordpress.com/377/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jameshalberg.wordpress.com/377/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jameshalberg.wordpress.com/377/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jameshalberg.wordpress.com/377/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jameshalberg.wordpress.com/377/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jameshalberg.wordpress.com/377/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jameshalberg.wordpress.com/377/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jameshalberg.wordpress.com/377/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jameshalberg.wordpress.com/377/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jameshalberg.wordpress.com/377/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jameshalberg.wordpress.com/377/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jameshalberg.wordpress.com/377/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jameshalberg.wordpress.com/377/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jameshalberg.wordpress.com&amp;blog=160606&amp;post=377&amp;subd=jameshalberg&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jameshalberg.wordpress.com/2009/11/25/friends-price/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">jameshalberg</media:title>
		</media:content>

		<media:content url="http://jameshalberg.files.wordpress.com/2009/11/firstpass.png" medium="image">
			<media:title type="html">firstpass</media:title>
		</media:content>
	</item>
		<item>
		<title>Ruby String Concatenation</title>
		<link>http://jameshalberg.wordpress.com/2008/10/27/ruby-string-concatenation/</link>
		<comments>http://jameshalberg.wordpress.com/2008/10/27/ruby-string-concatenation/#comments</comments>
		<pubDate>Tue, 28 Oct 2008 04:43:33 +0000</pubDate>
		<dc:creator>Jim</dc:creator>
				<category><![CDATA[rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[+=]]></category>
		<category><![CDATA[concatenation]]></category>
		<category><![CDATA[string]]></category>

		<guid isPermaLink="false">http://jameshalberg.wordpress.com/?p=167</guid>
		<description><![CDATA[Ran in to a bug tonight.  See it? def display_value display_value = notes.blank? ? "untitled" : notes display_value &#60;&#60; " (#{ shortcut })" unless shortcut.blank? display_value end Need a hint?  The symptom was the +notes+ field being unexpectedly changed. +display_value+ &#8230; <a href="http://jameshalberg.wordpress.com/2008/10/27/ruby-string-concatenation/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jameshalberg.wordpress.com&amp;blog=160606&amp;post=167&amp;subd=jameshalberg&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Ran in to a bug tonight.  See it?<br />
<code><br />
def display_value<br />
display_value = notes.blank? ? "untitled" : notes<br />
display_value &lt;&lt; " (#{ shortcut })" unless shortcut.blank?<br />
display_value<br />
end<br />
</code></p>
<p>Need a hint?  The symptom was the +notes+ field being unexpectedly changed.</p>
<p>+display_value+ is pointed at +notes+.  &#8220;&lt;&lt;&#8221; then goes ahead and changes that value (which both attributes are pointed at), thus both are effectively changed.</p>
<p>So, while it&#8217;s nice to avoid the extra String creation with &#8220;&lt;&lt;&#8221; where possible &#8211; sometimes, you&#8217;ve just gotta go with the &#8220;+=&#8221; to clone, then modify.</p>
<p><code><br />
a and b ending up the same:<br />
&gt;&gt; a = "a"<br />
=&gt; "a"<br />
&gt;&gt; b = a<br />
=&gt; "a"<br />
&gt;&gt; b &lt;&lt; "asomething"<br />
&gt;&gt; a.object_id == b.object_id<br />
=&gt; true<br />
</code></p>
<p><code><br />
and different:<br />
&gt;&gt; a = "a"<br />
=&gt; "a"<br />
&gt;&gt; b = a<br />
=&gt; "a"<br />
&gt;&gt; b += "something"<br />
=&gt; "asomething"<br />
&gt;&gt; a.object_id == b.object_id<br />
=&gt; false<br />
</code></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jameshalberg.wordpress.com/167/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jameshalberg.wordpress.com/167/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jameshalberg.wordpress.com/167/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jameshalberg.wordpress.com/167/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jameshalberg.wordpress.com/167/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jameshalberg.wordpress.com/167/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jameshalberg.wordpress.com/167/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jameshalberg.wordpress.com/167/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jameshalberg.wordpress.com/167/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jameshalberg.wordpress.com/167/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jameshalberg.wordpress.com/167/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jameshalberg.wordpress.com/167/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jameshalberg.wordpress.com/167/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jameshalberg.wordpress.com/167/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jameshalberg.wordpress.com&amp;blog=160606&amp;post=167&amp;subd=jameshalberg&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jameshalberg.wordpress.com/2008/10/27/ruby-string-concatenation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">jameshalberg</media:title>
		</media:content>
	</item>
		<item>
		<title>Rails Upgrade Bumps</title>
		<link>http://jameshalberg.wordpress.com/2008/07/07/rails-upgrade-bums/</link>
		<comments>http://jameshalberg.wordpress.com/2008/07/07/rails-upgrade-bums/#comments</comments>
		<pubDate>Tue, 08 Jul 2008 02:18:44 +0000</pubDate>
		<dc:creator>Jim</dc:creator>
				<category><![CDATA[rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[eager loading]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[partial updates]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://jameshalberg.wordpress.com/?p=127</guid>
		<description><![CDATA[After skimming the &#8220;What&#8217;s New&#8221; posts for several Rails versions without finding anything worth jumping at, it was time to upgrade.  While JSON enhancements (fixes) are the driving reason for the move, there certainly are a few &#8220;nice to haves&#8221; &#8230; <a href="http://jameshalberg.wordpress.com/2008/07/07/rails-upgrade-bums/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jameshalberg.wordpress.com&amp;blog=160606&amp;post=127&amp;subd=jameshalberg&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>After skimming the &#8220;What&#8217;s New&#8221; posts for several Rails versions without finding anything worth jumping at, it was time to upgrade.  While JSON enhancements (fixes) are the driving reason for the move, there certainly are a few &#8220;nice to haves&#8221; that I&#8217;ve been looking forward to checking out.</p>
<p> </p>
<p><strong>Partial Updates</strong></p>
<p>Unfortunately, one of the things I&#8217;ve been looking forward to completely falls flat in my book&#8230; Partial Updates (to some extent: Dirty Objects).  </p>
<p>When I first read the paragraph-blurb about this addition I was pretty impressed and was looking forward to seeing how it was implemented.  I was much less impressed when I got my head under the hood.  Relying totally on use of ActiveRecord setter methods is a pretty big fail in my book.  Tracking down every place that a field is edited &#8220;in place&#8221; to specially flag it (xyz_will_change) is completely unreasonable and maintaining that rule going forward is an annoyance that I just don&#8217;t need.</p>
<p>I played with several ways of attempting to set flags when changes were &#8220;likely&#8221; (ex: when getters were used) or always flagging &#8220;likely to be edited in place&#8221; attributes (ex: serialized fields) but just was ending up with lots of additional complexity, reduced reliability, and basically voiding out any gained efficiency.</p>
<p>Having this enabled by default (apparently the plan) is just plain confusing:  Seems much more reasonable to enabled this when you know it&#8217;s going to benefit you.  I also don&#8217;t like that it adds another question for a new developer to ask (or get tripped up on) when joining a project.  I really don&#8217;t want to have to read every line of the new guys code for the first three months to make sure that he&#8217;s sticking to the rules (and setting up tests to verify it explicitly).</p>
<p> </p>
<p><strong>XML handling</strong></p>
<p>Null values are now flagged as such instead of just being blank, like they would look if they were&#8230; uh&#8230; blank.  This is a good thing &#8211; it also tripped me up for a bit.</p>
<p> </p>
<p><strong>Eager Loading</strong></p>
<p>It seems eager loading has been changed a bit.  Statements that used to result in :include items being joined right into a single large query now (may) result in several smaller statements.  </p>
<p>Does it make queries more efficient?  Probably.</p>
<p>Does it increase db traffic?  Probably.</p>
<p>Is it a bad thing?  Probably Not (overall).</p>
<p>Is it a bad thing that stuff that worked before doesn&#8217;t?  Yeah, that&#8217;s annoying.</p>
<p>My specific problem is on an association defined with a :select =&gt; &#8220;distinct labels.*&#8221;.  I played around a bit with potential changes down in the AR guts but in the end (unfortunately) I ended up basically tricking it into running it as a single statement.  It&#8217;s not at all difficult to make it happen but it&#8217;s also not at all straightforward &#8211; and I hate it when the framework makes me write a big comment.</p>
<p>For me, I added an <img src='http://s1.wp.com/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> rder to my find that would make it order by something in a different table, which scares the thing into running a single statement.  Ideally, I&#8217;d like to have something explicit (maybe on the association but more likely on the find itself) that would allow an optional param to say &#8220;run this as one statement&#8221;.  That would let someone reading the code clearly see what&#8217;s going on &#8211; instead of wondering (or more likely: not noticing) that I&#8217;m ordering by some pointless field.</p>
<p> </p>
<p><strong>Overall</strong></p>
<p style="text-align:left;">Not nearly as bad as I had expected.  Felt good to get some deprecated stuff fixed and get some of my old TODOs out of there in the process.  Also good to have it (almost) over with and to, at least temporarily,<a href="http://bja.oxfordjournals.org/cgi/content/full/90/5/708">have caught up with the Joneses</a>.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/jameshalberg.wordpress.com/127/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/jameshalberg.wordpress.com/127/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jameshalberg.wordpress.com/127/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jameshalberg.wordpress.com/127/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jameshalberg.wordpress.com/127/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jameshalberg.wordpress.com/127/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jameshalberg.wordpress.com/127/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jameshalberg.wordpress.com/127/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jameshalberg.wordpress.com/127/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jameshalberg.wordpress.com/127/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jameshalberg.wordpress.com/127/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jameshalberg.wordpress.com/127/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jameshalberg.wordpress.com/127/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jameshalberg.wordpress.com/127/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jameshalberg.wordpress.com/127/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jameshalberg.wordpress.com/127/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jameshalberg.wordpress.com&amp;blog=160606&amp;post=127&amp;subd=jameshalberg&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jameshalberg.wordpress.com/2008/07/07/rails-upgrade-bums/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">jameshalberg</media:title>
		</media:content>
	</item>
		<item>
		<title>Is an association already loaded?</title>
		<link>http://jameshalberg.wordpress.com/2008/01/30/is-an-association-already-loaded/</link>
		<comments>http://jameshalberg.wordpress.com/2008/01/30/is-an-association-already-loaded/#comments</comments>
		<pubDate>Thu, 31 Jan 2008 03:25:59 +0000</pubDate>
		<dc:creator>Jim</dc:creator>
				<category><![CDATA[rails]]></category>
		<category><![CDATA[activerecord]]></category>
		<category><![CDATA[association]]></category>

		<guid isPermaLink="false">http://jameshalberg.wordpress.com/?p=107</guid>
		<description><![CDATA[If you can&#8217;t tell&#8230; I like posting little &#8220;cheatsheet&#8221; items here. So, here&#8217;s another one that I&#8217;ve bumped into again recently after not needing it for a while. You want to know how many Items are currently in the Store &#8230; <a href="http://jameshalberg.wordpress.com/2008/01/30/is-an-association-already-loaded/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jameshalberg.wordpress.com&amp;blog=160606&amp;post=107&amp;subd=jameshalberg&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>If you can&#8217;t tell&#8230; I like posting little &#8220;cheatsheet&#8221; items here.  So, here&#8217;s another one that I&#8217;ve bumped into again recently after not needing it for a while.</p>
<p>You want to know how many Items are currently in the Store and you&#8217;ve got this in your Store definition:<br />
<code>has_many :items</code></p>
<p>If the Items for this Store have already been read in and objects have been mapped, you simply want to ask for the count:<br />
<code>flagship_store.items.size</code></p>
<p>but if they haven&#8217;t already been mapped, you want to just do a quick select count(*):<br />
<code>Item.count(:conditions =&gt; ["store_id = ?", flagship_store.id])</code></p>
<p>The answer?</p>
<p>For many of us it&#8217;s:<br />
<code><br />
item_count = flagship_store.instance_variable_get(:@items) ? @items.size : Item.count(:conditions =&gt; ["store_id = ?", flagship_store.id])<br />
</code></p>
<p>And for those of you living in the future it&#8217;s even more straightforward:<br />
<code><br />
item_count = flagship_store.instance_variable_defined?(:@items) ? @items.size : Item.count(:conditions =&gt; ["store_id = ?", flagship_store.id])<br />
</code></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/jameshalberg.wordpress.com/107/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/jameshalberg.wordpress.com/107/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jameshalberg.wordpress.com/107/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jameshalberg.wordpress.com/107/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jameshalberg.wordpress.com/107/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jameshalberg.wordpress.com/107/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jameshalberg.wordpress.com/107/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jameshalberg.wordpress.com/107/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jameshalberg.wordpress.com/107/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jameshalberg.wordpress.com/107/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jameshalberg.wordpress.com/107/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jameshalberg.wordpress.com/107/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jameshalberg.wordpress.com/107/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jameshalberg.wordpress.com/107/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jameshalberg.wordpress.com/107/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jameshalberg.wordpress.com/107/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jameshalberg.wordpress.com&amp;blog=160606&amp;post=107&amp;subd=jameshalberg&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jameshalberg.wordpress.com/2008/01/30/is-an-association-already-loaded/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">jameshalberg</media:title>
		</media:content>
	</item>
		<item>
		<title>Nice(r) Hash treatment for URLs</title>
		<link>http://jameshalberg.wordpress.com/2007/11/14/nicer-hash-treatment-for-urls/</link>
		<comments>http://jameshalberg.wordpress.com/2007/11/14/nicer-hash-treatment-for-urls/#comments</comments>
		<pubDate>Wed, 14 Nov 2007 09:53:08 +0000</pubDate>
		<dc:creator>Jim</dc:creator>
				<category><![CDATA[rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[url_for]]></category>

		<guid isPermaLink="false">http://jameshalberg.wordpress.com/2007/11/14/nicer-hash-treatment-for-urls/</guid>
		<description><![CDATA[Isn&#8217;t it nice how Rails lets you add form elements using the convention: store[manager] = Bob Smith store[location][state] = Wisconsin store[location][zip] = 53590 And easily process them on the server side with something like: Store.new(params[:store]) So, why does this: link_to &#8230; <a href="http://jameshalberg.wordpress.com/2007/11/14/nicer-hash-treatment-for-urls/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jameshalberg.wordpress.com&amp;blog=160606&amp;post=93&amp;subd=jameshalberg&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Isn&#8217;t it nice how Rails lets you add form elements using the convention:</p>
<p>store[manager] = Bob Smith<br />
store[location][state] = Wisconsin<br />
store[location][zip] = 53590</p>
<p>And easily process them on the server side with something like:<br />
Store.new(params[:store])</p>
<p>So, why does this:<br />
link_to &#8220;Store&#8221;, :controller =&gt; :store, :action =&gt; :show, :store =&gt; { :manager =&gt; &#8220;Bob Smith&#8221;, :location =&gt; { :state =&gt; &#8220;Wisconsin&#8221;, :zip =&gt; 53590 } }</p>
<p>output something stupid like this:</p>
<p>http://localhost:3000/case/1/store/show?store=locationstateWisconsinzip53590managerBob+Smith</p>
<p>when what I&#8217;d like is something like:</p>
<p>http://localhost:3000/store/show?store%5Blocation%5D%5Bstate%5D=Wisconsin&#038;store%5Blocation%5D%5Bzip%5D=53590&#038;store%5Bmanager%5D=Bob+Smith</p>
<p>Well, without further ado, I give you the url_for hack to make it happen (note: For a widespread solution this would need to do a bit more&#8230; escape things, handle some different object types, handle more than 1 layer of hashed values, etc&#8230; but you get the idea)</p>
<p><a title="url_for_hack2.png" href="http://jameshalberg.files.wordpress.com/2007/11/url_for_hack2.png"><img src="http://jameshalberg.files.wordpress.com/2007/11/url_for_hack2.png?w=500" alt="url_for_hack2.png" /></a></p>
<p>Putting this in url_for has other benefits since lots of things depend on it.  For example, now you can do:</p>
<p>redirect_to :action =&gt; :show,  :store =&gt; { :manager =&gt; &#8220;Bob Smith&#8221;, :location =&gt; { :state =&gt; &#8220;Wisconsin&#8221;, :zip =&gt; 53590 } }</p>
<p>This is especially handy if you&#8217;d like an action to &#8220;hand off&#8221; some of the params that it&#8217;s received via a redirect.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/jameshalberg.wordpress.com/93/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/jameshalberg.wordpress.com/93/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jameshalberg.wordpress.com/93/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jameshalberg.wordpress.com/93/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jameshalberg.wordpress.com/93/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jameshalberg.wordpress.com/93/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jameshalberg.wordpress.com/93/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jameshalberg.wordpress.com/93/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jameshalberg.wordpress.com/93/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jameshalberg.wordpress.com/93/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jameshalberg.wordpress.com/93/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jameshalberg.wordpress.com/93/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jameshalberg.wordpress.com/93/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jameshalberg.wordpress.com/93/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jameshalberg.wordpress.com/93/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jameshalberg.wordpress.com/93/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jameshalberg.wordpress.com&amp;blog=160606&amp;post=93&amp;subd=jameshalberg&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jameshalberg.wordpress.com/2007/11/14/nicer-hash-treatment-for-urls/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">jameshalberg</media:title>
		</media:content>

		<media:content url="http://jameshalberg.files.wordpress.com/2007/11/url_for_hack2.png" medium="image">
			<media:title type="html">url_for_hack2.png</media:title>
		</media:content>
	</item>
		<item>
		<title>Links for blackberry&#8217;s</title>
		<link>http://jameshalberg.wordpress.com/2007/02/26/links-for-blackberrys/</link>
		<comments>http://jameshalberg.wordpress.com/2007/02/26/links-for-blackberrys/#comments</comments>
		<pubDate>Tue, 27 Feb 2007 01:19:45 +0000</pubDate>
		<dc:creator>Jim</dc:creator>
				<category><![CDATA[Email]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Blackberry]]></category>

		<guid isPermaLink="false">http://jameshalberg.wordpress.com/2007/02/26/links-for-blackberrys/</guid>
		<description><![CDATA[A user recently reported an issue with our emails. The issue being that our links weren&#8217;t properly coming through on his Blackberry unit, while links from others looked fine. After a bit of digging the issue ended up being that: &#8230; <a href="http://jameshalberg.wordpress.com/2007/02/26/links-for-blackberrys/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jameshalberg.wordpress.com&amp;blog=160606&amp;post=66&amp;subd=jameshalberg&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>A user recently reported an issue with our emails.  The issue being that our links weren&#8217;t properly coming through on his Blackberry unit, while links from others looked fine.</p>
<p>After a bit of digging the issue ended up being that:</p>
<p>&lt;a href=&#8221;http://seekingalpha.com&#8221;&gt;SA&lt;/a&gt;</p>
<p>displayed like this (which is desired on the unit):</p>
<p>SA &lt;http://seekingalpha.com&gt;</p>
<p>While this:</p>
<p>&lt;a href=&#8217;http://seekingalpha.com&#8217;&gt;SA&lt;/a&gt;</p>
<p>displayed:</p>
<p>SA</p>
<p>Not sure if ignoring links with single quotes is something on all Blackberries &#8211; just this unit &#8211; or even the way this particular unit is configured&#8230; but at least it&#8217;s not hard to fix once identified!</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/jameshalberg.wordpress.com/66/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/jameshalberg.wordpress.com/66/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jameshalberg.wordpress.com/66/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jameshalberg.wordpress.com/66/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jameshalberg.wordpress.com/66/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jameshalberg.wordpress.com/66/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jameshalberg.wordpress.com/66/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jameshalberg.wordpress.com/66/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jameshalberg.wordpress.com/66/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jameshalberg.wordpress.com/66/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jameshalberg.wordpress.com/66/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jameshalberg.wordpress.com/66/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jameshalberg.wordpress.com/66/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jameshalberg.wordpress.com/66/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jameshalberg.wordpress.com/66/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jameshalberg.wordpress.com/66/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jameshalberg.wordpress.com&amp;blog=160606&amp;post=66&amp;subd=jameshalberg&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jameshalberg.wordpress.com/2007/02/26/links-for-blackberrys/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">jameshalberg</media:title>
		</media:content>
	</item>
		<item>
		<title>Receiving Email with ActionMailer</title>
		<link>http://jameshalberg.wordpress.com/2006/12/06/receiving-email-with-actionmailer/</link>
		<comments>http://jameshalberg.wordpress.com/2006/12/06/receiving-email-with-actionmailer/#comments</comments>
		<pubDate>Wed, 06 Dec 2006 10:31:19 +0000</pubDate>
		<dc:creator>Jim</dc:creator>
				<category><![CDATA[Email]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Test Driven Development (TDD)]]></category>

		<guid isPermaLink="false">http://jameshalberg.wordpress.com/2006/12/06/receiving-email-with-actionmailer/</guid>
		<description><![CDATA[This really was a snap. A nice and simple testing recipe (#68) demonstrates how to read in an email from a fixture in just a few lines and pass them to your processing method (MailReceiver.receive in this case). def read_fixture(action) &#8230; <a href="http://jameshalberg.wordpress.com/2006/12/06/receiving-email-with-actionmailer/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jameshalberg.wordpress.com&amp;blog=160606&amp;post=60&amp;subd=jameshalberg&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This really was a snap.</p>
<p>A nice and simple <a href="http://www.pragmaticprogrammer.com/titles/fr_rr/">testing recipe</a> (#68) demonstrates how to read in an email from a fixture in just a few lines and pass them to your processing method (MailReceiver.receive in this case).</p>
<p><em>def read_fixture(action)<br />
IO.readlines(&#8220;#{FIXTURES_PATH}/mail_receiver/#{action}&#8221;)<br />
end</em></p>
<p><em>def test_something<br />
email = read_fixture(&#8220;junk_mail&#8221;).join<br />
MailReceiver.receive(email)</em><br />
<em># assertions<br />
end</em></p>
<p>And then a few lines on how to feed it <a href="http://wiki.rubyonrails.org/rails/pages/HowToReceiveEmailsWithActionMailer">&#8220;for real&#8221;</a>.  and we&#8217;re up and running!</p>
<p>The only catch&#8230; there was some anger over the parens:</p>
<pre>mailman: "|/path/to/app/script/runner Mailman.receive(STDIN.read)"</pre>
<p>We ended up escaping them, but according to those directions I just linked to &#8211; you can also just quote the call to receive.</p>
<pre></pre>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/jameshalberg.wordpress.com/60/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/jameshalberg.wordpress.com/60/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jameshalberg.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jameshalberg.wordpress.com/60/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jameshalberg.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jameshalberg.wordpress.com/60/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jameshalberg.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jameshalberg.wordpress.com/60/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jameshalberg.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jameshalberg.wordpress.com/60/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jameshalberg.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jameshalberg.wordpress.com/60/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jameshalberg.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jameshalberg.wordpress.com/60/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jameshalberg.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jameshalberg.wordpress.com/60/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jameshalberg.wordpress.com&amp;blog=160606&amp;post=60&amp;subd=jameshalberg&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jameshalberg.wordpress.com/2006/12/06/receiving-email-with-actionmailer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">jameshalberg</media:title>
		</media:content>
	</item>
		<item>
		<title>Be careful with assert_not_equal</title>
		<link>http://jameshalberg.wordpress.com/2006/10/02/be-careful-with-assert_not_equal/</link>
		<comments>http://jameshalberg.wordpress.com/2006/10/02/be-careful-with-assert_not_equal/#comments</comments>
		<pubDate>Mon, 02 Oct 2006 21:40:41 +0000</pubDate>
		<dc:creator>Jim</dc:creator>
				<category><![CDATA[rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Test Driven Development (TDD)]]></category>

		<guid isPermaLink="false">http://jameshalberg.wordpress.com/2006/10/02/be-careful-with-assert_not_equal/</guid>
		<description><![CDATA[As I discovered today, assert_not_equal has a pretty big problem: it does exactly what you ask it to do. I just need to make sure that a user has at least one record: assert_not_equal 0, UserPreference.find_by_user_id(user_id) As you may have &#8230; <a href="http://jameshalberg.wordpress.com/2006/10/02/be-careful-with-assert_not_equal/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jameshalberg.wordpress.com&amp;blog=160606&amp;post=57&amp;subd=jameshalberg&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>As I discovered today, assert_not_equal has a pretty big problem: it does exactly what you ask it to do.</p>
<p>I just need to make sure that a user has at least one record:</p>
<p><em>assert_not_equal 0, UserPreference.find_by_user_id(user_id)</em></p>
<p>As you may have just caught: that is always going to pass.  Not a tough mistake when you&#8217;re motoring along and not putting too much thought into something so simple:  The finder isn&#8217;t going to return the count of matching rows&#8230; it&#8217;s either going to return a populated object or nil, neither of which will be equal to 0.</p>
<p>Fixing the bug is trivial, but lesson learned:</p>
<p>From now on whenever I write assert_not_equal &#8211; I am going to make sure it works by temporarily changing it to assert_equal and taking a look at the error message.</p>
<p>In this case: if the error message said something like &#8220;&lt;0&gt; expected but was &lt;2&gt;&#8221;, I would know that things are working.</p>
<p>Whereas if the error said &#8220;&lt;0&gt; expected but was &lt;#&lt;UserPreference&#8230;&gt;&gt;&#8221;, I&#8217;d know right away that I need to fix it up (and have one more cup of coffee).</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/jameshalberg.wordpress.com/57/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/jameshalberg.wordpress.com/57/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jameshalberg.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jameshalberg.wordpress.com/57/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jameshalberg.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jameshalberg.wordpress.com/57/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jameshalberg.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jameshalberg.wordpress.com/57/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jameshalberg.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jameshalberg.wordpress.com/57/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jameshalberg.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jameshalberg.wordpress.com/57/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jameshalberg.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jameshalberg.wordpress.com/57/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jameshalberg.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jameshalberg.wordpress.com/57/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jameshalberg.wordpress.com&amp;blog=160606&amp;post=57&amp;subd=jameshalberg&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jameshalberg.wordpress.com/2006/10/02/be-careful-with-assert_not_equal/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">jameshalberg</media:title>
		</media:content>
	</item>
		<item>
		<title>Send an image</title>
		<link>http://jameshalberg.wordpress.com/2006/09/21/send-an-image/</link>
		<comments>http://jameshalberg.wordpress.com/2006/09/21/send-an-image/#comments</comments>
		<pubDate>Fri, 22 Sep 2006 02:36:41 +0000</pubDate>
		<dc:creator>Jim</dc:creator>
				<category><![CDATA[rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://jameshalberg.wordpress.com/2006/09/21/send-an-image/</guid>
		<description><![CDATA[You&#8217;d think it would be easy to send an image to a client with a framework as wonderful as Rails. After doing quite a bit of searching for the simple way, I really didn&#8217;t turn up too much. Finally, I &#8230; <a href="http://jameshalberg.wordpress.com/2006/09/21/send-an-image/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jameshalberg.wordpress.com&amp;blog=160606&amp;post=56&amp;subd=jameshalberg&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>You&#8217;d think it would be easy to send an image to a client with a framework as wonderful as Rails.</p>
<p>After doing quite a bit of searching for the simple way, I really didn&#8217;t turn up too much.  Finally, I decided I would just open the file and write it out the old fashioned way: using the File object.</p>
<p>Got that all done, but for some reason my content-type in the header wasn&#8217;t getting properly picked up so the receiving browser was thinking it was something to save to my desktop.  A quick look to make sure that my syntax was correct and there it was&#8230;</p>
<p>send_file(path, options={})</p>
<p>So, yeah.  To have your controller send an image back:</p>
<p>send_file &#8216;/the/path/image.png&#8217;</p>
<p>Pretty tough</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/jameshalberg.wordpress.com/56/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/jameshalberg.wordpress.com/56/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jameshalberg.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jameshalberg.wordpress.com/56/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jameshalberg.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jameshalberg.wordpress.com/56/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jameshalberg.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jameshalberg.wordpress.com/56/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jameshalberg.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jameshalberg.wordpress.com/56/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jameshalberg.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jameshalberg.wordpress.com/56/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jameshalberg.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jameshalberg.wordpress.com/56/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jameshalberg.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jameshalberg.wordpress.com/56/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jameshalberg.wordpress.com&amp;blog=160606&amp;post=56&amp;subd=jameshalberg&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jameshalberg.wordpress.com/2006/09/21/send-an-image/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">jameshalberg</media:title>
		</media:content>
	</item>
	</channel>
</rss>
