<?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>MemeRocket &#187; Ruby on Rails</title>
	<atom:link href="http://memerocket.com/category/ruby-on-rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://memerocket.com</link>
	<description>Bill Burcham's Launch Platform</description>
	<lastBuildDate>Sun, 19 Feb 2012 03:56:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='memerocket.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://0.gravatar.com/blavatar/048c0b3b1b3b5279e320104a4b5d0bb0?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>MemeRocket &#187; Ruby on Rails</title>
		<link>http://memerocket.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://memerocket.com/osd.xml" title="MemeRocket" />
	<atom:link rel='hub' href='http://memerocket.com/?pushpress=hub'/>
		<item>
		<title>Eastern US is Fertile Ground for Ruby Development</title>
		<link>http://memerocket.com/2009/07/23/eastern-us-is-fertile-ground-for-ruby-development/</link>
		<comments>http://memerocket.com/2009/07/23/eastern-us-is-fertile-ground-for-ruby-development/#comments</comments>
		<pubDate>Thu, 23 Jul 2009 22:53:08 +0000</pubDate>
		<dc:creator>Bill Burcham</dc:creator>
				<category><![CDATA[marketing]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://memerocket.com/?p=261</guid>
		<description><![CDATA[As I was perusing jobs on Rubynow I thought I was seeing a concentration of jobs in Florida, New England, and the Washington DC area. To test the idea a little, I decided to throw a sampling of the recent &#8230; <a href="http://memerocket.com/2009/07/23/eastern-us-is-fertile-ground-for-ruby-development/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=memerocket.com&#038;blog=5432592&#038;post=261&#038;subd=memerocket&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div id="attachment_264" class="wp-caption alignright" style="width: 209px"><a href="http://maps.google.com/maps/ms?ie=UTF8&amp;hl=en&amp;msa=0&amp;msid=115685239335565937159.00046f6521d21e93b15c8&amp;ll=35.532226,-76.904297&amp;spn=22.457995,38.891602&amp;z=5"><img class="size-medium wp-image-264" title="Eastern US Ruby Jobs and Consultancies" src="http://memerocket.files.wordpress.com/2009/07/picture-2.png?w=199&h=300" alt="Eastern US Ruby Jobs and Consultancies" width="199" height="300" /></a><p class="wp-caption-text">Eastern US Ruby Jobs and Consultancies</p></div>
<p>As I was perusing jobs on <a title="Rubynow Jobs" href="http://jobs.rubynow.com">Rubynow</a> I thought I was seeing a concentration of jobs in Florida, New England, and the Washington DC area. To test the idea a little, I decided to throw a sampling of the recent jobs onto a map (see <a title="some Ruby Jobs and Consultancies" href="http://maps.google.com/maps/ms?ie=UTF8&amp;hl=en&amp;msa=0&amp;msid=115685239335565937159.00046f6521d21e93b15c8&amp;ll=36.031332,-78.134766&amp;spn=22.320975,38.891602&amp;z=5">Ruby on Jobs and Consultancies</a> »). To that map I also added some of my favorite Ruby consultancies:</p>
<ul>
<li><a title="ENTP" href="http://entp.com/">ENTP</a> (Portland, OR)</li>
<li><a title="Hashrocket" href="http://www.hashrocket.com/">Hashrocket</a> (Jacksonville Beach, FL)</li>
<li><a title="Intridea" href="http://intridea.com/">Intridea</a> (Washington, DC)</li>
<li><a title="Planet Argon" href="http://planetargon.com/">Planet Argon</a> (Portland, OR)</li>
<li><a title="thoughtbot" href="http://thoughtbot.com/">thoughtbot</a> (Boston, MA)</li>
<li><a title="Thought Propulsion - iPhone and Web Design and Development" href="http://www.thoughtpropulsion.com/">Thought Propulsion</a> (Portland, OR) « hey that&#8217;s me »</li>
<li><a title="Viget" href="http://www.viget.com">Viget</a> (Falls Church, VA)</li>
</ul>
<p>If you look at the whole (world) map I think you will agree that there is a definite concentration of Ruby jobs and kickass consultancies in the Eastern US. There are many biases at work here of course, especially when it comes to the consultancies I&#8217;ve listed. Nevertheless, it does seem like something&#8217;s going on here.</p>
<p>I&#8217;m intrigued by a few points:</p>
<p>What&#8217;s going on down there in Florida? Seems like I see lots of Ruby jobs down there.</p>
<p>What&#8217;s up with that DC area. I&#8217;d say the presence of Intridea and Viget within what, 10 miles of each other qualifies DC as a hotbed.</p>
<p>Look at that New England cluster. I think there is general awareness a big presence in New York, but the number of jobs in New England surprised me.</p>
<p>What is it about the Eastern US that makes it such fertile ground for Ruby? Is there some bias in the job listings on Rubynow? Or is this simply a reflection of Ruby moving into the enterprise. Is there a particular kind of enterprise that&#8217;s predominant in the East and that&#8217;s adopting Ruby technology?</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/memerocket.wordpress.com/261/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/memerocket.wordpress.com/261/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/memerocket.wordpress.com/261/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/memerocket.wordpress.com/261/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/memerocket.wordpress.com/261/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/memerocket.wordpress.com/261/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/memerocket.wordpress.com/261/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/memerocket.wordpress.com/261/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/memerocket.wordpress.com/261/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/memerocket.wordpress.com/261/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/memerocket.wordpress.com/261/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/memerocket.wordpress.com/261/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/memerocket.wordpress.com/261/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/memerocket.wordpress.com/261/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=memerocket.com&#038;blog=5432592&#038;post=261&#038;subd=memerocket&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://memerocket.com/2009/07/23/eastern-us-is-fertile-ground-for-ruby-development/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a88a8da103044de18418f303bf0c1507?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">bburcham</media:title>
		</media:content>

		<media:content url="http://memerocket.files.wordpress.com/2009/07/picture-2.png?w=199" medium="image">
			<media:title type="html">Eastern US Ruby Jobs and Consultancies</media:title>
		</media:content>
	</item>
		<item>
		<title>Are Ruby Session ID&#8217;s Secure?</title>
		<link>http://memerocket.com/2008/10/14/are-ruby-session-ids-secure/</link>
		<comments>http://memerocket.com/2008/10/14/are-ruby-session-ids-secure/#comments</comments>
		<pubDate>Wed, 15 Oct 2008 01:47:15 +0000</pubDate>
		<dc:creator>Bill Burcham</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://meme-rocket.com/2008/10/14/are-ruby-session-ids-secure/</guid>
		<description><![CDATA[The question of the security of cookie-based session storage in Rails has pretty much been settled it seems to me. Out of the box, Rails uses cookie-based session storage. When you generate a new Rails app you get a nice &#8230; <a href="http://memerocket.com/2008/10/14/are-ruby-session-ids-secure/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=memerocket.com&#038;blog=5432592&#038;post=110&#038;subd=memerocket&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The question of the security of cookie-based session storage in Rails has pretty much been settled it seems to me. <a href="http://ryandaigle.com/articles/2007/2/21/what-s-new-in-edge-rails-cookie-based-sessions">Out of the box</a>, Rails uses cookie-based session storage. When you generate a new Rails app you get a nice new 128 character long (numbers and lowercase letters) secret set in config.action_controller.session[:secret] in your Rails::Initializer. That secret is used to sign and validate cookies for your application. Now the cookie data isn&#8217;t secret mind you, but it is tamper-proof. Good.</p>
<p>Now what if you don&#8217;t use cookie-based session storage at all? Well, just because you aren&#8217;t using cookie-based session storage doesn&#8217;t mean you aren&#8217;t using cookies. If your application has sessions at all, be they memcached ones or ActiveRecord ones, it is probably using cookies. It&#8217;s using cookies to <a href="http://www.quarkruby.com/2007/10/21/sessions-and-cookies-in-ruby-on-rails#sinrails">store the session id</a> so that when a request arrives, that id can be mapped to the corresponding session storage.</p>
<p>&#8220;So what&#8221; you say. &#8220;Well&#8221; I say… isn&#8217;t it cool that Rails generates that big random secret for you when you use cookie-based session storage? When we are not using cookie-based session storage, and that secret is not generated, don&#8217;t you wonder what secret is being used to secure your session id&#8217;s? You see, a <a href="http://www.technicalinfo.net/papers/WebBasedSessionManagement.html">session id must be hard to guess</a> lest bad people <a href="http://www.cgisecurity.com/lib/SessionIDs.pdf">gain access to your site</a>. Usually when you want to make something hard to guess, you start with a secret and mix that with something that changes a lot and hash the whole shebang. So I went in search of this other secret.</p>
<p>What I found was that Rails calls <a href="http://corelib.rubyonrails.org/classes/CGI/Session.html#M000366">CGI::Session#create_new_id</a> to generate new session id&#8217;s. That routine uses no secrete per se. It hashes (MD5) a combination of:</p>
<ol>
<li>the current date and time (expressed as a human-readable string)</li>
<li>the microseconds elapsed since the last second (expressed as a human-readable string)</li>
<li>a pseudo-random number greater than zero and less than one (from Kernel#rand)</li>
<li>the current process id number</li>
<li>the string &#8216;foobar&#8217;</li>
</ol>
<p>Notice there is no secret keying material there. &#8220;But what about the Kernel#rand call Bill!&#8221; I hear you saying. If you go have a look at <a href="http://www.ruby-doc.org/core/classes/Kernel.html#M005977">Kernel#rand</a> and <a href="http://www.ruby-doc.org/core/classes/Kernel.html#M005976">Kernel#srand</a> you&#8217;ll see that if rand is called before srand is called with a number parameter then the random number will be generated from a combination of:</p>
<ol>
<li>the current time</li>
<li>the process id number</li>
</ol>
<p>So the security of these session ids hinges on the secrecy of current time (on the server running Ruby) and the process id. Given that the system time is returned in HTTP headers and process id&#8217;s are often in the hundreds or thousands, it&#8217;s only really the microseconds that are hard to guess here, from a statistical standpoint. <a href="http://www.nycbsdcon.org/2006/files/BSDRailsBenninger.pdf">Others have expressed</a> similar concerns.</p>
<p>If you&#8217;re worried about this two suggestions come to mind:</p>
<ul>
<li>time out sessions on the server so that an attacker has to guess faster</li>
<li>monkey-patch <a href="http://corelib.rubyonrails.org/classes/CGI/Session.html#M000366">CGI::Session#create_new_id</a> to hash its result with a great big old 128 character secret</li>
</ul>
<p><strong>Updated</strong>: October 15, 2008 expanded analysis of Kernel#rand and Kernel#srand and updated suggestions.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/memerocket.wordpress.com/110/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/memerocket.wordpress.com/110/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/memerocket.wordpress.com/110/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/memerocket.wordpress.com/110/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/memerocket.wordpress.com/110/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/memerocket.wordpress.com/110/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/memerocket.wordpress.com/110/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/memerocket.wordpress.com/110/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/memerocket.wordpress.com/110/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/memerocket.wordpress.com/110/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/memerocket.wordpress.com/110/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/memerocket.wordpress.com/110/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/memerocket.wordpress.com/110/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/memerocket.wordpress.com/110/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=memerocket.com&#038;blog=5432592&#038;post=110&#038;subd=memerocket&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://memerocket.com/2008/10/14/are-ruby-session-ids-secure/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a88a8da103044de18418f303bf0c1507?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">bburcham</media:title>
		</media:content>
	</item>
		<item>
		<title>Thought Propulsion™ is Go For Burn</title>
		<link>http://memerocket.com/2008/09/25/thought-propulsion%e2%84%a2-is-go-for-burn/</link>
		<comments>http://memerocket.com/2008/09/25/thought-propulsion%e2%84%a2-is-go-for-burn/#comments</comments>
		<pubDate>Thu, 25 Sep 2008 16:47:14 +0000</pubDate>
		<dc:creator>Bill Burcham</dc:creator>
				<category><![CDATA[design]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[OpenID]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Web as Platform]]></category>

		<guid isPermaLink="false">http://meme-rocket.com/2008/09/25/thought-propulsion%e2%84%a2-is-go-for-burn/</guid>
		<description><![CDATA[The Thought Propulsion™ corporate site is up and running. For the technically inclined, here are some interesting facts: hosted on Amazon EC2 using the extremely slick EC2 On Rails Ubuntu/Ruby on Rails virtual appliance there&#8217;s a tasty microformatted hcard on &#8230; <a href="http://memerocket.com/2008/09/25/thought-propulsion%e2%84%a2-is-go-for-burn/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=memerocket.com&#038;blog=5432592&#038;post=109&#038;subd=memerocket&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><img style="float:left;margin-top:10px;margin-bottom:10px;margin-right:20px;" src="http://thoughtpropulsion.com/images/logo.png" />
<p>The <a href="http://thoughtpropulsion.com/">Thought Propulsion™</a> corporate site is up and running. For the technically inclined, here are some interesting facts:</p>
<ul>
<li>hosted on <a href="http://aws.amazon.com/">Amazon EC2</a></li>
<li>using the extremely slick <a href="http://ec2onrails.rubyforge.org/">EC2 On Rails</a> Ubuntu/Ruby on Rails <a href="http://en.wikipedia.org/wiki/Virtual_appliance">virtual appliance</a></li>
<li>there&#8217;s a tasty microformatted <a href="http://microformats.org/wiki/hcard">hcard</a> on the <a href="http://thoughtpropulsion.com/contact">contact</a> page (check it out with <a href="https://addons.mozilla.org/en-US/firefox/addon/4106">Operator</a>)</li>
<li>OpenID login (<span style="font-style:italic;">foreshadowing</span>)</li>
</ul>
<p>And of course a nice gray and orange theme just in time for Halloween.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/memerocket.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/memerocket.wordpress.com/109/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/memerocket.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/memerocket.wordpress.com/109/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/memerocket.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/memerocket.wordpress.com/109/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/memerocket.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/memerocket.wordpress.com/109/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/memerocket.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/memerocket.wordpress.com/109/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/memerocket.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/memerocket.wordpress.com/109/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/memerocket.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/memerocket.wordpress.com/109/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=memerocket.com&#038;blog=5432592&#038;post=109&#038;subd=memerocket&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://memerocket.com/2008/09/25/thought-propulsion%e2%84%a2-is-go-for-burn/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a88a8da103044de18418f303bf0c1507?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">bburcham</media:title>
		</media:content>

		<media:content url="http://thoughtpropulsion.com/images/logo.png" medium="image" />
	</item>
		<item>
		<title>Rails Vendor Branch Limbo</title>
		<link>http://memerocket.com/2008/06/20/rails-vendor-branch-limbo/</link>
		<comments>http://memerocket.com/2008/06/20/rails-vendor-branch-limbo/#comments</comments>
		<pubDate>Fri, 20 Jun 2008 20:28:33 +0000</pubDate>
		<dc:creator>Bill Burcham</dc:creator>
				<category><![CDATA[One Step Forward]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://meme-rocket.com/2008/06/20/rails-vendor-branch-limbo/</guid>
		<description><![CDATA[I&#8217;m upgrading a project from Rails 2.0.2 to Rails 2.1. This thing uses Comatose 0.8.1. Unfortunately, Comatose 0.8.1 isn&#8217;t compatible with Rails 2.1. Fine, I&#8217;ll just upgrade to Comatose 2.0 (uber-alpha) and that&#8217;ll work. Oops, Comatose 2.0 uber-alpha breaks Rails &#8230; <a href="http://memerocket.com/2008/06/20/rails-vendor-branch-limbo/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=memerocket.com&#038;blog=5432592&#038;post=106&#038;subd=memerocket&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div style="text-align:left;"><span class="photo_container pc_m"><a href="http://www.flickr.com/photos/cwalker71/2482546331/" title="Stick Figure (6)"><img style="float:left;margin-top:10px;margin-bottom:10px;margin-right:10px;" src="http://farm3.static.flickr.com/2307/2482546331_130e605362_m.jpg" alt="Stick Figure (6)" class="pc_img" width="240" height="160" /></a></span>I&#8217;m upgrading a project from Rails 2.0.2 to Rails 2.1. </div>
<p>This thing uses Comatose 0.8.1. Unfortunately, Comatose 0.8.1 isn&#8217;t compatible with Rails 2.1. Fine, I&#8217;ll just upgrade to <a href="http://github.com/darthapo/comatose/tree/master">Comatose 2.0 (uber-alpha)</a> and that&#8217;ll work. Oops, Comatose 2.0 uber-alpha <a href="http://groups.google.com/group/comatose-plugin/browse_thread/thread/e6402c29de92edc7">breaks Rails migrations</a>. Fixing that breakage requires a <a href="http://pastie.textmate.org/181667">patch to Rails itself</a>.</p>
<p>Oh and did I mention that this project of mine also requires a <a href="http://code.google.com/p/comatose-plugin/issues/detail?id=20&amp;q=before_filters#makechanges">patch to Comatose</a> proper (adds before_filters to the Comatose configuration object).</p>
<p>So I need a patched version of Comatose and a patched version of Rails. “OK” you say, just use <a href="http://piston.rubyforge.org/">Piston</a> to manage those vendor branches. Not so fast. Piston only works with Subversion and the Rails project is no longer hosted on a Subversion repository. The <a href="http://dev.rubyonrails.org/svn/rails/tags/">old repository</a> was <a href="http://dev.rubyonrails.org/svn/rails/tags/">deprecated</a> after Rails 2.0.2. Rails is now hosted on Github. Oh and so is Comatose.</p>
<p>Never fear, Github support for Piston is coming <a href="http://blog.teksol.info/2008/3/15/piston-2-0-progress-piston-can-import-all-four-cases">Real Soon Now</a>™. Until then I&#8217;m stuck in limbo. I suppose I&#8217;ll do the <a href="http://lookfirst.com/2007/11/subversion-vendor-branches-howto.html">manual vendor branch</a> thing—essentially manage my own private Subversion repositories for Rails and Comatose.</p>
<p>The fact that <a href="http://blog.teksol.info/">François Beausoleil</a> is implementing Piston support for all-Git projects leads me to believe that there is no convenient alternative (to Piston) for vendor branches in Git. Hum, that&#8217;s hard to believe. Anyhow, I can&#8217;t migrate this project to Git yet so all-Git alternatives are sort of moot.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/memerocket.wordpress.com/106/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/memerocket.wordpress.com/106/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/memerocket.wordpress.com/106/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/memerocket.wordpress.com/106/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/memerocket.wordpress.com/106/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/memerocket.wordpress.com/106/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/memerocket.wordpress.com/106/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/memerocket.wordpress.com/106/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/memerocket.wordpress.com/106/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/memerocket.wordpress.com/106/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/memerocket.wordpress.com/106/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/memerocket.wordpress.com/106/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/memerocket.wordpress.com/106/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/memerocket.wordpress.com/106/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/memerocket.wordpress.com/106/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/memerocket.wordpress.com/106/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=memerocket.com&#038;blog=5432592&#038;post=106&#038;subd=memerocket&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://memerocket.com/2008/06/20/rails-vendor-branch-limbo/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a88a8da103044de18418f303bf0c1507?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">bburcham</media:title>
		</media:content>

		<media:content url="http://farm3.static.flickr.com/2307/2482546331_130e605362_m.jpg" medium="image">
			<media:title type="html">Stick Figure (6)</media:title>
		</media:content>
	</item>
		<item>
		<title>Agnostic Unobtrusive JavaScript</title>
		<link>http://memerocket.com/2007/09/07/agnostic-unobtrusive-javascript/</link>
		<comments>http://memerocket.com/2007/09/07/agnostic-unobtrusive-javascript/#comments</comments>
		<pubDate>Fri, 07 Sep 2007 17:53:53 +0000</pubDate>
		<dc:creator>Bill Burcham</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[RJS templates]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://www.meme-rocket.com/2007/09/07/agnostic-unobtrusive-javascript/</guid>
		<description><![CDATA[A few weeks ago I wrote about Unobtrusive JavaScript using the Prototype versus JQuery stacks. In that post I came down on the side of the JQuery stack. Something I didn&#8217;t analyze at the time, was: is it possible to &#8230; <a href="http://memerocket.com/2007/09/07/agnostic-unobtrusive-javascript/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=memerocket.com&#038;blog=5432592&#038;post=86&#038;subd=memerocket&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>A few weeks ago I wrote about <a href="http://www.meme-rocket.com">Unobtrusive JavaScript using the Prototype versus JQuery stacks</a>. In that post I came down on the side of the JQuery stack. Something I didn&#8217;t analyze at the time, was: is it possible to use a little of each? For instance, say (hypothetically) that you have a big old Rails project that uses RJS all over the place and you&#8217;d like to continue using RJS &#8212; is there a way to leverage pieces of JQuery in that scenario.</p>
<p>In this pursuit I learned a few things. Firstly, plain old JQuery does not &#8220;do&#8221; UJS in the following sense: if you bind a behavior to an element (via a CSS selector), that binding will not be reapplied as the DOM is manipulated. For dynamic binding, or &#8220;live&#8221; binding that gets re-applied after every DOM update, you need Brandon Aaron&#8217;s <a href="http://brandonaaron.net/docs/livequery/">livequery</a> plugin for JQuery. Livequery is to JQuery as Dan Webb&#8217;s <a href="http://www.danwebb.net/lowpro">Low Pro</a> is to Prototype &#8212; kind of. Difference being that livequery hooks each of JQuery&#8217;s DOM manipulation routines, whereas Low Pro hooks each of Prototype&#8217;s Ajax.Responders &#8220;onComplete&#8221; event &#8212; the event that happens when an <a href="http://en.wikipedia.org/wiki/XMLHttpRequest">XHR</a> is complete.</p>
<p>What all this means is that you can use JQuery&#8217;s UJS (livequery) if you use JQuery for all your DOM manipulations, or you can use Prototypes UJS (Low Pro) if you use Prototype for all your Ajax calls. The unfortunate bit is that you cannot (yet) use livequery with Prototype Ajax calls, or Low Pro with JQuery DOM manipulations. Can&#8217;t we all just get along?</p>
<p>I wonder if a UJS package could remain stack agnostic. I think livequery is on to something by hooking DOM manipulation routines. That seems more robust (if potentially less performant) than hooking the Ajax returns. By hooking DOM manipulation  it seems that you&#8217;ve plugged more holes and have a more general-purpose solution. Could the livequery approach (of watching for DOM manipulation) be done in a stack-agnostic fashion rather than by hooking JQuery routines? If we could do that then we&#8217;d have a UJS package we could use no matter which JavaScript base library we choose &#8212; or perhaps whichever <a href="http://www.hogwartsprofessor.com/?p=107">library chooses us</a>.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/memerocket.wordpress.com/86/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/memerocket.wordpress.com/86/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/memerocket.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/memerocket.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/memerocket.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/memerocket.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/memerocket.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/memerocket.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/memerocket.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/memerocket.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/memerocket.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/memerocket.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/memerocket.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/memerocket.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/memerocket.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/memerocket.wordpress.com/86/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=memerocket.com&#038;blog=5432592&#038;post=86&#038;subd=memerocket&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://memerocket.com/2007/09/07/agnostic-unobtrusive-javascript/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a88a8da103044de18418f303bf0c1507?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">bburcham</media:title>
		</media:content>
	</item>
		<item>
		<title>UJS; RJS versus POJS; Prototype Stack versus JQuery Stack</title>
		<link>http://memerocket.com/2007/08/17/ujs-rjs-versus-pojs-prototype-stack-versus-jquery-stack/</link>
		<comments>http://memerocket.com/2007/08/17/ujs-rjs-versus-pojs-prototype-stack-versus-jquery-stack/#comments</comments>
		<pubDate>Fri, 17 Aug 2007 18:29:18 +0000</pubDate>
		<dc:creator>Bill Burcham</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[RJS templates]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[script.aculo.us]]></category>

		<guid isPermaLink="false">http://www.meme-rocket.com/2007/08/17/ujs-rjs-versus-pojs-prototype-stack-versus-jquery-stack/</guid>
		<description><![CDATA[I am accustomed to using Unobtrusive JavaScript (UJS) in my apps. UJS dynamically adds event handlers to the DOM. These event handers implement behaviors via DOM manipulations and XMLHttpRequests (XHR&#8217;s). This approach is in contrast to the historical approach of &#8230; <a href="http://memerocket.com/2007/08/17/ujs-rjs-versus-pojs-prototype-stack-versus-jquery-stack/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=memerocket.com&#038;blog=5432592&#038;post=85&#038;subd=memerocket&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I am accustomed to using <a href="http://en.wikipedia.org/wiki/Unobtrusive_JavaScript">Unobtrusive JavaScript</a> (UJS) in my apps. UJS dynamically adds event handlers to the DOM. These event handers implement behaviors via DOM manipulations and XMLHttpRequests (XHR&#8217;s). This approach is in contrast to the historical approach of specifying event handlers on HTML elements directly. The value of the UJS approach are:</p>
<ul>
<li>it separates behavior (JavaScript) from markup (HTML) and this is good for the same reasons separating style (CSS) from markup is good</li>
<li>it can reduce page weight</li>
</ul>
<p>I had been using <a href="http://www.ujs4rails.com/">ujs4rails</a> but that thing is being <a href="http://www.danwebb.net/2007/6/16/the-state-and-future-of-the-ujs-plugin">deprecated</a> so it isn&#8217;t an option for me.  If I want to do UJS I can either use Prototype or JQuery. I don&#8217;t know of any other good options.</p>
<p>I&#8217;m using JQuery a bit now. Pretty light use: a highlight effect here, a show/hide toggle there; some AJAX form submission. In thinking about how to proceed I&#8217;m kind of torn. I don&#8217;t want to use both JQuery and Prototype longer term. For starters, that&#8217;s too much mental baggage to carry around &#8212; one must gain fluency in one or &#8216;tother I think. Also it&#8217;s a lot of page weight to load both libraries.</p>
<p>Another dimension is RJS vs. POJS. RJS is Rails&#8217; templating and API that lets you generate JavaScript from Ruby. POJS is &#8220;Plain Old JavaScript&#8221;. If we do RJS then we almost have to stay on the Prototype stack. But with POJS a guy could go with either stack and in fact I think the scale tips to the JQuery stack for POJS as I&#8217;ll show in a sec.</p>
<p>So here&#8217;s how I see the top two options:</p>
<p>RJS: Prototype + Scriptaculous + RJS + Dan Webb&#8217;s <a href="http://www.danwebb.net/lowpro">Lowpro</a>:<br />
+ Lowpro supports UJS<br />
+ most of us have used prototype + scriptaculous and are somewhat comfortable with it<br />
+ native Rails (RJS) support<br />
-  Lowpro is not as well documented (nor as widely used) as JQuery for UJS<br />
-  I see no centralized library of plugins  (other than Scriptaculous itself) for this stack</p>
<p>POJS: JQuery + <a href="http://www.danwebb.net/2006/11/24/minusmor-released">MinusMOR</a>:<br />
+ it supports UJS out of the box in a pretty clean way<br />
+ people I respect seem to be moving to JQuery<br />
+ there is a large library of <a href="http://jquery.com/plugins/">plugins</a> including autocompleters and flash upload progress indicators<br />
- very little native Rails (RJS) support &#8212; <a href="http://mad.ly/2007/05/17/jquery-ajax-rails/">you can do some things</a> but it&#8217;s hard to know exactly what will work<br />
- if you already know scriptaculous effects, you have to learn new effects</p>
<p>A big part of this decision hinges on the value of RJS. After <a href="http://www.meme-rocket.com/category/rjs-templates/">using</a> Rails RJS templates for a year and a half or so my conclusion is that they are more trouble than they are worth. Many believe RJS is easier to write/maintain that POJS &#8212; especially for a Ruby programmer. I believe RJS is actually a <a href="http://en.wikipedia.org/wiki/False_economy">false economy</a>. In real applications you really have to code in real JavaScript.</p>
<p>An RJS template generates JavaScript from Ruby code &#8212; but that Ruby API is insufficiently documented (in particular with regard to the scriptaculous effects) and insufficiently capable (e.g. there is <a href="http://www.meme-rocket.com/2007/07/05/id-proliferation-eradication-technique-1-leverage-pageselect-with-pageinsert/">no easy way</a> to update DOM elements matching a CSS selector through that API). Essentially a guy can waste a lot of time trying to get RJS to work for anything but the simplest demos. <strong>So I lean toward plain-old JavaScript (POJS) instead</strong>.</p>
<p>I wonder what you think. Do you place higher value on RJS for real applications? Have you found an alternate stack, or perhaps a different combination of stack elements? Must I pick one stack or the other, or is it possible and profitable to use both at once?</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/memerocket.wordpress.com/85/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/memerocket.wordpress.com/85/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/memerocket.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/memerocket.wordpress.com/85/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/memerocket.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/memerocket.wordpress.com/85/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/memerocket.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/memerocket.wordpress.com/85/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/memerocket.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/memerocket.wordpress.com/85/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/memerocket.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/memerocket.wordpress.com/85/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/memerocket.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/memerocket.wordpress.com/85/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/memerocket.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/memerocket.wordpress.com/85/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=memerocket.com&#038;blog=5432592&#038;post=85&#038;subd=memerocket&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://memerocket.com/2007/08/17/ujs-rjs-versus-pojs-prototype-stack-versus-jquery-stack/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a88a8da103044de18418f303bf0c1507?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">bburcham</media:title>
		</media:content>
	</item>
		<item>
		<title>Logging From Your Rails Models</title>
		<link>http://memerocket.com/2007/08/05/logging-from-your-rails-models/</link>
		<comments>http://memerocket.com/2007/08/05/logging-from-your-rails-models/#comments</comments>
		<pubDate>Sun, 05 Aug 2007 16:41:49 +0000</pubDate>
		<dc:creator>Bill Burcham</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://www.meme-rocket.com/2007/08/05/logging-from-your-rails-models/</guid>
		<description><![CDATA[update 2010/10/16: RAILS_DEFAULT_LOGGER is deprecated. I&#8217;m using ActiveRecord::Base.logger now as in: ActiveRecord::Base.logger.debug "value of x is #{x}" read on for the older solution… I just spent five minutes figuring out how to log from a model class in Rails (or &#8230; <a href="http://memerocket.com/2007/08/05/logging-from-your-rails-models/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=memerocket.com&#038;blog=5432592&#038;post=84&#038;subd=memerocket&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>update 2010/10/16</strong>: <a href="https://rails.lighthouseapp.com/projects/8994/tickets/5141-deprecationproxy-for-rails_default_logger-hides-original-warn-method">RAILS_DEFAULT_LOGGER is deprecated</a>. I&#8217;m using ActiveRecord::Base.logger now as in:</p>
<pre style="padding-left:30px;">ActiveRecord::Base.logger.debug "value of x is #{x}"</pre>
<p>read on for the older solution…</p>
<p>I just spent five minutes figuring out how to log from a model class in Rails (or any class that isn&#8217;t a controller or view). Y&#8217;see, there is no &#8220;logger&#8221; method on an ActiveRecord for instance.  Once again <a href="http://www.robbyonrails.com/articles/tag/logging">Robby to the rescue</a> with an oblique mention of the RAILS_DEFAULT_LOGGER global. I love that guy.</p>
<p>Related: I wonder what <a href="http://ruby.jamisbuck.org/rails-injected.html#s10">Jamis circa &#8217;05</a> was talking about when he said:</p>
<blockquote><p><em>Note: logging is a bad example here, because Rails already has very good support for logging. Furthermore, recent Rails releases support a <em>service</em> keyword, for declaring and using system-global services in the same manner described here.</em></p></blockquote>
<p>Huh? Service keyword?</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/memerocket.wordpress.com/84/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/memerocket.wordpress.com/84/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/memerocket.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/memerocket.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/memerocket.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/memerocket.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/memerocket.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/memerocket.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/memerocket.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/memerocket.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/memerocket.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/memerocket.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/memerocket.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/memerocket.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/memerocket.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/memerocket.wordpress.com/84/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=memerocket.com&#038;blog=5432592&#038;post=84&#038;subd=memerocket&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://memerocket.com/2007/08/05/logging-from-your-rails-models/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a88a8da103044de18418f303bf0c1507?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">bburcham</media:title>
		</media:content>
	</item>
		<item>
		<title>Ruby Symbol#to_proc — Don’t Forget It!</title>
		<link>http://memerocket.com/2007/08/02/ruby-symbolto_proc-dont-forget-it/</link>
		<comments>http://memerocket.com/2007/08/02/ruby-symbolto_proc-dont-forget-it/#comments</comments>
		<pubDate>Fri, 03 Aug 2007 00:08:23 +0000</pubDate>
		<dc:creator>Bill Burcham</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://www.meme-rocket.com/2007/08/02/ruby-symbolto_proc-dont-forget-it/</guid>
		<description><![CDATA[This is your code: puts %w{A B}.collect{&#124;e&#124; e.downcase}.inspect This is my cooler code: puts %w{A B}.collect( &#38;:downcase).inspect This is how the Ruby Extension Project makes it work: class Symbol def to_proc proc { &#124;obj, *args&#124; obj.send(self, *args) } end end &#8230; <a href="http://memerocket.com/2007/08/02/ruby-symbolto_proc-dont-forget-it/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=memerocket.com&#038;blog=5432592&#038;post=83&#038;subd=memerocket&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This is your code:</p>
<pre><code>puts %w{A B}.collect{|e| e.downcase}.inspect</code></pre>
<p>This is my cooler code:</p>
<pre><code>puts %w{A B}.collect( &amp;:downcase).inspect</code></pre>
<p>This is how the Ruby Extension Project makes it work:</p>
<pre><code>class Symbol
  def to_proc
    proc { |obj, *args| obj.send(self, *args) }
  end
end</code></pre>
<p>This is the <a href="http://pragdave.pragprog.com/pragdave/2005/11/symbolto_proc.html">explanation</a>.</p>
<p>This is the <a href="http://errtheblog.com/post/44">love</a> (see day 38).</p>
<p>Don&#8217;t ever forget this.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/memerocket.wordpress.com/83/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/memerocket.wordpress.com/83/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/memerocket.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/memerocket.wordpress.com/83/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/memerocket.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/memerocket.wordpress.com/83/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/memerocket.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/memerocket.wordpress.com/83/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/memerocket.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/memerocket.wordpress.com/83/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/memerocket.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/memerocket.wordpress.com/83/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/memerocket.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/memerocket.wordpress.com/83/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/memerocket.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/memerocket.wordpress.com/83/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=memerocket.com&#038;blog=5432592&#038;post=83&#038;subd=memerocket&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://memerocket.com/2007/08/02/ruby-symbolto_proc-dont-forget-it/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a88a8da103044de18418f303bf0c1507?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">bburcham</media:title>
		</media:content>
	</item>
		<item>
		<title>Migration of Rails Development from PowerBook to MacBook Pro Marred by Annoying OS X File Sharing</title>
		<link>http://memerocket.com/2007/07/20/migration-of-rails-development-from-powerbook-to-macbook-pro-marred-by-annoying-os-x-file-sharing/</link>
		<comments>http://memerocket.com/2007/07/20/migration-of-rails-development-from-powerbook-to-macbook-pro-marred-by-annoying-os-x-file-sharing/#comments</comments>
		<pubDate>Fri, 20 Jul 2007 16:34:58 +0000</pubDate>
		<dc:creator>Bill Burcham</dc:creator>
				<category><![CDATA[OS X]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://www.meme-rocket.com/2007/07/20/migration-of-rails-development-from-powerbook-to-macbook-pro-marred-by-annoying-os-x-file-sharing/</guid>
		<description><![CDATA[Well I spent yesterday getting the new computer in shape and it&#8217;ll now run all my Rails projects. Overall the process has been surprisingly easy. The initial 45 minute FireWire brain transfer was extremely effective. After that, most productivity apps &#8230; <a href="http://memerocket.com/2007/07/20/migration-of-rails-development-from-powerbook-to-macbook-pro-marred-by-annoying-os-x-file-sharing/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=memerocket.com&#038;blog=5432592&#038;post=81&#038;subd=memerocket&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Well I spent yesterday getting the new computer in shape and it&#8217;ll now run all my Rails projects. Overall the process has been surprisingly easy. The initial 45 minute FireWire brain transfer was extremely effective. After that, most productivity apps Just Workedâ„¢. Loves me some Universal Binaries.</p>
<p>For the Rails folks out there I thought you&#8217;d be interested to know that this time around I chose to use Locomotive for my Rails stack and it has mostly worked very well. Last time I configured a brand new development machine (late &#8217;05) I went through the heck of installing a slew of ports for all the pieces (ruby, gem, gems, app server, web server, etc.) This time around I eschewed the 14 pages of instructions in favor of the single download and got myself some needed RMagick support in the bargain. I had successfully put off installing RMagick for about 18 months (thanks Captchator!) but recently started a project that just had to have RMagick. If you wonder why I&#8217;ve been avoiding RMagick then read this.</p>
<p>In moving my development environment from the old machine to the new, mysql didn&#8217;t automatically come over the firewire so I had to download and install it on the new machine. I needed to dump the database and move it to the new machine and load it. Turns out that moving that file over was about the most annoying part of this whole process.</p>
<p>So I created the dump on the old machine:</p>
<p><code>mysqldump -u root -pyour-password-here --single-transaction --all-databases &gt; mysql_backup.sql</code></p>
<p>And then went into System Preferences/Sharing and turned on Personal File Sharing. On the new machine I saw the shared directory, but the newly created file wasn&#8217;t there. All the other files were there. I&#8217;ve seen this before and presume it must be some sort of caching or timing issue. Old files show up, new files don&#8217;t. And of course there is no way to &#8220;refresh&#8221; a finder view.</p>
<p>So I switched gears and tried &#8220;FTP Access&#8221; in Sharing. Neither Transmit nor Interarchy were able to connect via FTP to the old machine. Finally, a friend recommended SFTP (SSH SFTP). And um, after clicking on each option in Sharing I saw that &#8220;Remote Login&#8221; mentions SSH so I thought I&#8217;d run that and sure enough I was able to use SFTP via Transmit to get the file. Whew.</p>
<p>Once the database dump was moved over I simply loaded it on the new database server. Remember a newly created mysql database has no passwords.</p>
<p><code>mysql &lt; mysql_backup.sql</code></p>
<p>You&#8217;ll notice that logins you brought over don&#8217;t work until you restart mysqld. Once you do that, you&#8217;re database has been replicated and your various logins and security restrictions will be in effect.</p>
<p>One other odd thing (besides the file sharing annoyance) was that while Locomotive purports to be a Universal Binary application it doesn&#8217;t actually work properly after the firewire transfer. It seemed like it was working &#8212; the application itself ran and it would actually start certain Rails apps. Problems had to do with RMagick not working (there&#8217;s a recurring theme here :) My solution was to reinstall Locomotive and the RMagick bundle afresh. After that everything worked great.</p>
<p>To summarize, here&#8217;s the main things I did to move my Rails development from PowerBook to MacBook Pro:</p>
<p>   1. run the automatic firewire system transfer to get most of your environment moved over<br />
   2. install Apple Software Updates and reboot (you should do this early on with any new machine)<br />
   3. install mySQL 5.0<br />
   4. dump mySQL database on old machine, transfer file using &#8220;remote login&#8221; and SFTP, load database on new machine and reboot mySQL<br />
   5. install X Code 2.4.1<br />
   6. re-install Locomotive (even though it transferred via Firewire):<br />
         1. move Applications/Locomotive2 to trash<br />
         2. download/install Locomotive<br />
   7. install Locomotive RMagick bundle if you need it<br />
   8. finally, under the Locomotive Terminal I had to install a few gems for my projects: ruby-debug, chronic</p>
<p>That&#8217;s pretty much it. All my Rails projects are up and running on the new machine. A little faster and with 60px less vertical space to work with. Not nearly as bad as it might have otherwise been I suppose.</p>
<p>Bear in mind these are not complete instructions for getting from a clean MacBook Pro to a Rails development environment. This is just about migrating from the PowerPC to Intel with a minimum of pain. It&#8217;s been pretty painless so far. Time will tell how well the Locomotive choice holds up. I&#8217;ll keep you updated.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/memerocket.wordpress.com/81/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/memerocket.wordpress.com/81/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/memerocket.wordpress.com/81/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/memerocket.wordpress.com/81/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/memerocket.wordpress.com/81/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/memerocket.wordpress.com/81/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/memerocket.wordpress.com/81/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/memerocket.wordpress.com/81/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/memerocket.wordpress.com/81/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/memerocket.wordpress.com/81/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/memerocket.wordpress.com/81/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/memerocket.wordpress.com/81/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/memerocket.wordpress.com/81/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/memerocket.wordpress.com/81/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/memerocket.wordpress.com/81/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/memerocket.wordpress.com/81/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=memerocket.com&#038;blog=5432592&#038;post=81&#038;subd=memerocket&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://memerocket.com/2007/07/20/migration-of-rails-development-from-powerbook-to-macbook-pro-marred-by-annoying-os-x-file-sharing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a88a8da103044de18418f303bf0c1507?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">bburcham</media:title>
		</media:content>
	</item>
		<item>
		<title>:has_many Associations with Complex Joins (Kind of)</title>
		<link>http://memerocket.com/2007/07/06/has_many-associations-with-complex-joins-kind-of/</link>
		<comments>http://memerocket.com/2007/07/06/has_many-associations-with-complex-joins-kind-of/#comments</comments>
		<pubDate>Sat, 07 Jul 2007 01:17:03 +0000</pubDate>
		<dc:creator>Bill Burcham</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://www.meme-rocket.com/2007/07/06/has_many-associations-with-complex-joins-kind-of/</guid>
		<description><![CDATA[In this episode, your fearless Jedi delves within the dark tree of associations, with_scope, inner joins, duck typing and meta-programming all in an effort to keep DRY&#8230; In Joyomi I create an Omi when I lend you a book. I &#8230; <a href="http://memerocket.com/2007/07/06/has_many-associations-with-complex-joins-kind-of/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=memerocket.com&#038;blog=5432592&#038;post=78&#038;subd=memerocket&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-196" title="duck-vader" src="http://memerocket.files.wordpress.com/2007/07/duck-vader.jpg?w=520" alt="duck-vader"   />In this episode, your fearless Jedi delves within the dark tree of associations, with_scope, inner joins, duck typing and meta-programming all in an effort to keep DRY&#8230;</p>
<p>In <a title="joyomi" href="http://joyomi.com">Joyomi</a> I create an Omi when I lend you a book. I can optionally share that Omi with you. If I do, then the Omi shows up in the &#8220;Omis Shared With Me&#8221; tab in your dashboard. Sharing. Mkay. Social networking 101.</p>
<p>Now the query for a Joyomi user to find his own Omi&#8217;s (one&#8217;s he&#8217;s created) is trivial. The user model simply has_many omis. No brainer. On the other hand, going in the opposite direction and finding all the Omi&#8217;s that my friends have shared with me is decidedly non-trivial. In fact it&#8217;s downright tricky. It involves a big long series of joins. This is further complicated by the fact that in order to address potential SPAMming we don&#8217;t show you Omi&#8217;s that were created by folks who are not in your contact list. Got that? Good.</p>
<p><span id="more-78"></span></p>
<p>So I set out to implement the &#8220;Omis Shared With Me&#8221; tab hoping to reuse a lot of stuff from the &#8220;Outstanding Omis&#8221; and &#8220;Archived Omis&#8221; tabs. In particular I&#8217;ve got a nice clean little pagination routine that takes an association as a parameter and then proceeds to paginate the Omis in that association. Here&#8217;s the routine:</p>
<pre class="textmate-source twilight"><span class="linenum">    1</span> <span class="source source_ruby"><span class="declaration declaration_function declaration_function_method declaration_function_method_with-arguments declaration_function_method_with-arguments_ruby">  <span class="keyword keyword_control keyword_control_def keyword_control_def_ruby">def</span> <span class="entity entity_name entity_name_function entity_name_function_ruby">paginate_omis</span>(<span class="variable variable_parameter"> association, order</span>)</span>
<span class="linenum">    2</span>     <span class="variable variable_other variable_other_readwrite variable_other_readwrite_instance variable_other_readwrite_instance_ruby">@omis_pages</span> = <span class="variable variable_other variable_other_constant variable_other_constant_ruby">Paginator</span>.<span class="keyword keyword_other keyword_other_special-method keyword_other_special-method_ruby">new</span> <span class="constant constant_language constant_language_pseudo-variable constant_language_pseudo-variable_ruby">self</span>, association.count, <span class="constant constant_numeric constant_numeric_ruby">10</span>, params[<span class="constant constant_other constant_other_symbol constant_other_symbol_ruby">:page</span>]
<span class="linenum">    3</span>     <span class="variable variable_other variable_other_readwrite variable_other_readwrite_instance variable_other_readwrite_instance_ruby">@omis</span> = association.find(
<span class="linenum">    4</span>       <span class="constant constant_other constant_other_symbol constant_other_symbol_ruby">:all</span>,
<span class="linenum">    5</span>       <span class="constant constant_other constant_other_symbol constant_other_symbol_ruby">:order</span> =&gt; order,
<span class="linenum">    6</span>       <span class="constant constant_other constant_other_symbol constant_other_symbol_ruby">:limit</span> =&gt; <span class="variable variable_other variable_other_readwrite variable_other_readwrite_instance variable_other_readwrite_instance_ruby">@omis_pages</span>.items_per_page,
<span class="linenum">    7</span>       <span class="constant constant_other constant_other_symbol constant_other_symbol_ruby">:offset</span> =&gt; <span class="variable variable_other variable_other_readwrite variable_other_readwrite_instance variable_other_readwrite_instance_ruby">@omis_pages</span>.current.offset)
<span class="linenum">    8</span>   <span class="keyword keyword_control keyword_control_ruby">end</span>
</span></pre>
<p>(the order parameter lets you send in nice little SQL ordering clauses like <a title="Put Nulls Last" href="/2006/12/02/put-nulls-last-on-mysql/">&#8216;-expected_at DESC&#8217;</a> ) You can see this routine relies on the association parameter responding to count and find. Since &#8220;outstanding&#8221; and &#8220;archived&#8221; Omis are associations:</p>
<pre class="textmate-source twilight"><span class="linenum">    1</span> <span class="source source_ruby">  has_many <span class="constant constant_other constant_other_symbol constant_other_symbol_ruby">:outstanding_omis</span>, <span class="constant constant_other constant_other_symbol constant_other_symbol_ruby">:class_name</span> =&gt; <span class="string string_quoted string_quoted_single string_quoted_single_ruby">'Omi'</span>, <span class="constant constant_other constant_other_symbol constant_other_symbol_ruby">:conditions</span> =&gt; <span class="string string_quoted string_quoted_double string_quoted_double_ruby">"`archived_at` is null"</span>
<span class="linenum">    2</span>   has_many <span class="constant constant_other constant_other_symbol constant_other_symbol_ruby">:archived_omis</span>, <span class="constant constant_other constant_other_symbol constant_other_symbol_ruby">:class_name</span> =&gt; <span class="string string_quoted string_quoted_single string_quoted_single_ruby">'Omi'</span>, <span class="constant constant_other constant_other_symbol constant_other_symbol_ruby">:conditions</span> =&gt; <span class="string string_quoted string_quoted_double string_quoted_double_ruby">"`archived_at` is not null"</span>
</span></pre>
<p>This works fine. So when it came time to implement &#8220;Omis Shared With Me&#8221; I thought great, I&#8217;ll just add another association for that. Granted this is a more complex association, but from reading about the :joins option  to <a title="find" href="http://caboo.se/doc/classes/ActiveRecord/Base.html#M006434">ActiveRecord::Base#find</a> it seemed doable. I&#8217;d just use that :joins option on my new association and everything would Just Workâ„¢. Boy was I wrong.</p>
<p>You may wonder why I would think that just because :joins was documented under find, that it would also work for has_many. Well it&#8217;s because those two methods mostly implement the same options.</p>
<h3>Options Implemented by Both find and has_many</h3>
<ul>
<li>:conditions</li>
<li>:order</li>
<li>:group</li>
<li>:limit</li>
<li>:offset</li>
<li>:include</li>
<li>:select</li>
</ul>
<p>But as it turns out there are a handful of discrepancies. Most of the discrepancies make sense. For instance, it wouldn&#8217;t make sense for find to support a :foreign_key option. But there are a few discrepancies that do not really make sense.</p>
<h3>Options <em>Implemented by find</em> but not by has_many</h3>
<ul>
<li><em>:joins</em></li>
<li>:readonly</li>
<li>:lock</li>
</ul>
<p>Hum, it seems to me that all three of these options would be useful on has_many. I groveled around the Rails source and I don&#8217;t see any particular reason why these aren&#8217;t supported by has_many. In fact it turns out that the find and has_many sources have many similarities. They just happen to have very little reuse going on.</p>
<p>It occured to me while reading the Rails source and seeing all the duplication between find and associations that there was a missing class, perhaps it should be called a &#8220;relation&#8221;. I&#8217;d like to instantiate a &#8220;relation&#8221; as a first class object. If such an object existed then both find and has_many could certainly use one. But that is the subject of a different post. I digress.</p>
<p>So finding myself in need of an association with :joins I did what any self-respecting Ruby programmer would do &#8212; I made one myself. Now before you freak out, I didn&#8217;t implement all 23-odd methods of has_many associations. I implemented only the two I needed in my pagination method (find and count). Remember, in Ruby, if it quacks like a duck that&#8217;s good enough. And I knew exactly which duck sounds this &#8220;association&#8221; would be called upon to emit.</p>
<p>So here is what the has_many would look like if has_many actually supported :joins:</p>
<pre class="textmate-source twilight"><span class="linenum">    1</span> <span class="source source_ruby source_ruby_rails"><span class="support support_function support_function_activerecord support_function_activerecord_rails">has_many</span> <span class="constant constant_other constant_other_symbol constant_other_symbol_ruby">:omis_shared_with_me</span>, <span class="constant constant_other constant_other_symbol constant_other_symbol_ruby">:class_name</span> =&gt; <span class="string string_quoted string_quoted_single string_quoted_single_ruby">'Omi'</span>, <span class="constant constant_other constant_other_symbol constant_other_symbol_ruby">:joins</span> =&gt; <span class="string string_quoted string_quoted_single string_quoted_single_ruby">'inner join identities as i2 on i2.id = omis.identity_id inner join email_addresses as e1 on e1.address = i2.name inner join contacts as c1 on c1.id = e1.contact_id inner join contacts as c2 on omis.counterparty_id = c2.id inner join email_addresses as e2 on c2.id = e2.contact_id'</span>, <span class="constant constant_other constant_other_symbol constant_other_symbol_ruby">:conditions</span> =&gt; <span class="string string_quoted string_quoted_single string_quoted_single_ruby">'identities.id = c1.owner_id and e2.address = identities.name'</span>
</span></pre>
<p>My workaround was to define a method on the user class (model). That method would return an instance of my new &#8220;association&#8221; class. Here is the method:</p>
<pre class="textmate-source twilight"><span class="linenum">    1</span> <span class="source source_ruby"><span class="declaration declaration_function declaration_function_method declaration_function_method_with-arguments declaration_function_method_with-arguments_ruby">  <span class="keyword keyword_control keyword_control_def keyword_control_def_ruby">def</span> <span class="entity entity_name entity_name_function entity_name_function_ruby">omis_shared_with_me</span>(<span class="variable variable_parameter"> *args</span>)</span>
<span class="linenum">    2</span>     proxy = <span class="variable variable_other variable_other_constant variable_other_constant_ruby">Object</span>.<span class="keyword keyword_other keyword_other_special-method keyword_other_special-method_ruby">new</span>
<span class="linenum">    3</span>     instance_eval &lt;&lt;<span class="keyword keyword_control keyword_control_ruby">END</span>
<span class="linenum">    4</span> <span class="declaration declaration_class declaration_class_ruby">    <span class="keyword keyword_control keyword_control_class keyword_control_class_ruby">class</span> <span class="entity entity_name entity_name_class entity_name_class_ruby"><span class="variable variable_other variable_other_object variable_other_object_ruby">&lt;&lt;proxy</span></span></span>
<span class="linenum">    5</span> <span class="declaration declaration_function declaration_function_method declaration_function_method_with-arguments declaration_function_method_with-arguments_ruby">      <span class="keyword keyword_control keyword_control_def keyword_control_def_ruby">def</span> <span class="entity entity_name entity_name_function entity_name_function_ruby">find</span>(<span class="variable variable_parameter"> *args</span>)</span>
<span class="linenum">    6</span>         with_scope <span class="keyword keyword_control keyword_control_ruby keyword_control_ruby_start-block">do
</span><span class="linenum">    7</span>           <span class="variable variable_other variable_other_constant variable_other_constant_ruby">Omi</span>.find( <span class="constant constant_other constant_other_symbol constant_other_symbol_ruby">:all</span>, *args)
<span class="linenum">    8</span>         <span class="keyword keyword_control keyword_control_ruby">end</span>
<span class="linenum">    9</span>       <span class="keyword keyword_control keyword_control_ruby">end</span>
<span class="linenum">   10</span> <span class="declaration declaration_function declaration_function_method declaration_function_method_with-arguments declaration_function_method_with-arguments_ruby">      <span class="keyword keyword_control keyword_control_def keyword_control_def_ruby">def</span> <span class="entity entity_name entity_name_function entity_name_function_ruby">count</span>(<span class="variable variable_parameter"> *args</span>)</span>
<span class="linenum">   11</span>         with_scope <span class="keyword keyword_control keyword_control_ruby keyword_control_ruby_start-block">do
</span><span class="linenum">   12</span>           <span class="variable variable_other variable_other_constant variable_other_constant_ruby">Omi</span>.count( *args)
<span class="linenum">   13</span>         <span class="keyword keyword_control keyword_control_ruby">end</span>
<span class="linenum">   14</span>       <span class="keyword keyword_control keyword_control_ruby">end</span>
<span class="linenum">   15</span>       <span class="keyword keyword_other keyword_other_special-method keyword_other_special-method_ruby">private</span>
<span class="linenum">   16</span> <span class="declaration declaration_function declaration_function_method declaration_function_method_without-arguments declaration_function_method_without-arguments_ruby">      <span class="keyword keyword_control keyword_control_def keyword_control_def_ruby">def</span> <span class="entity entity_name entity_name_function entity_name_function_ruby">with_scope</span></span>
<span class="linenum">   17</span>         <span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby"># without :select omis.* you get superfluous columns an the Omi objects aren't right (description is often NULL)</span>
<span class="linenum">   18</span>         <span class="variable variable_other variable_other_constant variable_other_constant_ruby">Omi</span>.with_scope(<span class="constant constant_other constant_other_symbol constant_other_symbol_ruby">:find</span> =&gt; {<span class="meta meta_syntax meta_syntax_ruby meta_syntax_ruby_start-block"> </span><span class="constant constant_other constant_other_symbol constant_other_symbol_ruby">:select</span> =&gt; <span class="string string_quoted string_quoted_single string_quoted_single_ruby">'omis.*'</span>, <span class="constant constant_other constant_other_symbol constant_other_symbol_ruby">:joins</span> =&gt; <span class="string string_quoted string_quoted_single string_quoted_single_ruby">'inner join identities as i2 on i2.id = omis.identity_id inner join email_addresses as e1 on e1.address = i2.name inner join contacts as c1 on c1.id = e1.contact_id inner join identities as i1 on i1.id = c1.owner_id inner join contacts as c2 on omis.counterparty_id = c2.id inner join email_addresses as e2 on c2.id = e2.contact_id'</span>, <span class="constant constant_other constant_other_symbol constant_other_symbol_ruby">:conditions</span> =&gt; [<span class="string string_quoted string_quoted_single string_quoted_single_ruby">'e2.address = i1.name and :identity_id = i1.id'</span>, {<span class="constant constant_other constant_other_symbol constant_other_symbol_ruby">:identity_id</span> =&gt; <span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby">#{id}}]}) do</span>
<span class="linenum">   19</span>           <span class="keyword keyword_control keyword_control_pseudo-method keyword_control_pseudo-method_ruby">yield</span>
<span class="linenum">   20</span>         <span class="keyword keyword_control keyword_control_ruby">end</span>
<span class="linenum">   21</span>       <span class="keyword keyword_control keyword_control_ruby">end</span> <span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby"># def</span>
<span class="linenum">   22</span>     <span class="keyword keyword_control keyword_control_ruby">end</span> <span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby"># &lt;&lt;proxy</span>
<span class="linenum">   23</span> <span class="keyword keyword_control keyword_control_ruby">END</span>
<span class="linenum">   24</span>     proxy
<span class="linenum">   25</span>   <span class="keyword keyword_control keyword_control_ruby">end</span> <span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby"># def</span></span></pre>
<p>This code bears some explanation. (darn tootin!) The most obvious way to define the association class would be to simply define a new Ruby class at the top level or maybe within the scope of the user class. If we did that however, we wouldn&#8217;t have access, in instances of that class, to the id attribute of the user. And we need that id when the association is called upon to do its thing.</p>
<p>Now we could add an instance variable to our association class to hold the id and we could initialize that thing on construction but that wouldn&#8217;t be very educational now would it? Nope, no instance variables for us &#8212; we&#8217;re going to use a little meta-programming instead.</p>
<p>So instead of defining the new class at the top level or in the context of the user <em>class</em>, we define an object-specific class (specific to the proxy object) and we evaluate that definition in the context of the user <em>object</em>. In this way, the reference to id in the private with_scope method will reference the id attribute of the appropriate user at runtime.</p>
<p>So that&#8217;s it. We are leveraging find to create an association class that supports the :joins option in 25 lines of code. This approach could easily be extended to add some of the other methods of has_many depending on your project needs. Also, I&#8217;m sure some Ruby Rock Star could DRY it up more.</p>
<p><img title="The Thing With Two Heads" src="http://www.meme-rocket.com/wp-content/uploads/2007/07/two-heads.jpg" alt="The Thing With Two Heads" align="right" />On the other hand, doing a whole lot more to turn this <a title="Kiczales' Hematoma Metaphor" href="http://www2.parc.com/csl/groups/sda/projects/oi/workshop-94/foil/main.html">hematoma</a> into a <a title="Thing With Two Heads" href="http://www.imdb.com/title/tt0069372/">second head</a> is not a very wise use of resources. It&#8217;d be interesting to go in and steal (factor out) the best bits of find and has_many and build that general purpose &#8216;relation&#8217; class I spoke of earlier, DRY-ing up find and associations, normalizing the options between them and giving us first-class &#8216;relations&#8217; to boot. Anyone of you ActiveRecord warriors out there interested in some deep hacking?</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/memerocket.wordpress.com/78/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/memerocket.wordpress.com/78/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/memerocket.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/memerocket.wordpress.com/78/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/memerocket.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/memerocket.wordpress.com/78/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/memerocket.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/memerocket.wordpress.com/78/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/memerocket.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/memerocket.wordpress.com/78/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/memerocket.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/memerocket.wordpress.com/78/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/memerocket.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/memerocket.wordpress.com/78/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/memerocket.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/memerocket.wordpress.com/78/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=memerocket.com&#038;blog=5432592&#038;post=78&#038;subd=memerocket&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://memerocket.com/2007/07/06/has_many-associations-with-complex-joins-kind-of/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a88a8da103044de18418f303bf0c1507?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">bburcham</media:title>
		</media:content>

		<media:content url="http://memerocket.files.wordpress.com/2007/07/duck-vader.jpg" medium="image">
			<media:title type="html">duck-vader</media:title>
		</media:content>

		<media:content url="http://www.meme-rocket.com/wp-content/uploads/2007/07/two-heads.jpg" medium="image">
			<media:title type="html">The Thing With Two Heads</media:title>
		</media:content>
	</item>
	</channel>
</rss>
