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

<channel>
	<title>Frenzic Mojo</title>
	<atom:link href="http://www.frenzicmojo.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.frenzicmojo.net</link>
	<description>A boy and his blog</description>
	<lastBuildDate>Tue, 10 Nov 2009 04:29:56 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Fun with jQuery datepicker and Facebox</title>
		<link>http://www.frenzicmojo.net/2009/11/fun-with-jquery-datepicker-and-facebox/</link>
		<comments>http://www.frenzicmojo.net/2009/11/fun-with-jquery-datepicker-and-facebox/#comments</comments>
		<pubDate>Tue, 10 Nov 2009 04:27:30 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[datepicker]]></category>
		<category><![CDATA[facebox]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://www.frenzicmojo.net/?p=92</guid>
		<description><![CDATA[I know, big surprise, something stops working in facebox. In this case, it&#8217;s datepicker, which is actually a pretty nice little date selection plugin. Unfortunately, it uses HTML element ID attributes in order to function, and that means it all falls apart when facebox clones the HTML. After fiddling with it for a while, I [...]]]></description>
			<content:encoded><![CDATA[<p>I know, big surprise, something stops working in facebox. In this case, it&#8217;s datepicker, which is actually a pretty nice little date selection plugin. Unfortunately, it uses HTML element ID attributes in order to function, and that means it all falls apart when facebox clones the HTML. After fiddling with it for a while, I figured out the following:</p>
<p>First, you have to deal with that pesky ID problem. Thankfully, you can use jQuery selectors to find the datepicker fields, and then the plugin will determine the IDs dynamically. Which means you don&#8217;t have to know the IDs before hand. So, you just bind a method to the facebox.reveal event to change the IDs, like so:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">jQuery<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'reveal.facebox'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#facebox .datepicker'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>intIndex<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    jQuery<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'id'</span><span style="color: #339933;">,</span>jQuery<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'id'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'-2'</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Of course, it is possible that those field IDs are important to you, In which case, when you need to refer to them you should remember that you appended that &#8216;-2&#8242; to the end of the ID.</p>
<p>The next problem is that datepicker initiates after the page loads, which means that when facebox clones the HTML to display, the new date field won&#8217;t have initialized. This is simply solved by adding some more code to the binding the initialize method to the facebox.reveal event, instead of the page load. Like so:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">jQuery<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'reveal.facebox'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#facebox .datepicker'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>intIndex<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    jQuery<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'id'</span><span style="color: #339933;">,</span>jQuery<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'id'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'-2'</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#facebox .datepicker'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">datepick</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    alignment<span style="color: #339933;">:</span> <span style="color: #3366CC;">'bottomLeft'</span><span style="color: #339933;">,</span>
    buttonImageOnly<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>
    buttonImage<span style="color: #339933;">:</span> <span style="color: #3366CC;">'/images/calendar_date_select/calendar.gif'</span><span style="color: #339933;">,</span>
    showOn<span style="color: #339933;">:</span> <span style="color: #3366CC;">'both'</span><span style="color: #339933;">,</span>
    showStatus<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#facebox [name=field_name]'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">datepick</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'option'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'onSelect'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>value<span style="color: #339933;">,</span> date<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#facebox [name=field_name]'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span>value<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>There you go, now it initializes when the facebox loads. Problem solved.</p>
<p>Or is it?</p>
<p>It just happens that my particular implementation involved more than one facebox, each with it&#8217;s own datepicker. Suddenly, all of my well thought out hacks fall apart, and nothing works again.</p>
<p>There&#8217;s probably a prettier way to fix this, but I needed the solution to be modular. A given facebox might appear on one page by itself, and on another page with several others. I needed to solve the conflict without breaking the independence, so I ended up wrapping the whole script in an if statement that checks for an element on a given form.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">jQuery<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'reveal.facebox'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#facebox [name=model[field]]'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">length</span><span style="color: #339933;">&gt;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#facebox .datepicker'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>intIndex<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      jQuery<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'id'</span><span style="color: #339933;">,</span>jQuery<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'id'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'-2'</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#facebox .datepicker'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">datepick</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
      alignment<span style="color: #339933;">:</span> <span style="color: #3366CC;">'bottomLeft'</span><span style="color: #339933;">,</span>
      buttonImageOnly<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>
      buttonImage<span style="color: #339933;">:</span> <span style="color: #3366CC;">'/images/calendar_date_select/calendar.gif'</span><span style="color: #339933;">,</span>
      showOn<span style="color: #339933;">:</span> <span style="color: #3366CC;">'both'</span><span style="color: #339933;">,</span>
      showStatus<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#facebox [name=field_name]'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">datepick</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'option'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'onSelect'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>value<span style="color: #339933;">,</span> date<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#facebox [name=field_name]'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span>value<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Not pretty, I know. Especially, since the above code is replicated everywhere a facebox with a datepicker field appears on the page, sometimes multiple times on one page. It works, though. That&#8217;s the important thing, right?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.frenzicmojo.net/2009/11/fun-with-jquery-datepicker-and-facebox/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Joys of Open Source</title>
		<link>http://www.frenzicmojo.net/2009/04/the-joys-of-open-source/</link>
		<comments>http://www.frenzicmojo.net/2009/04/the-joys-of-open-source/#comments</comments>
		<pubDate>Thu, 09 Apr 2009 16:41:37 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[db_free_solr]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://www.frenzicmojo.net/?p=64</guid>
		<description><![CDATA[A while back, I tweeted about how cool it was to have a software patch I submitted be accepted.
You know what&#8217;s cooler than that?
Realizing that someone is actually using a plugin I wrote.
I mean, working with open source, when you put something like that out there, it&#8217;s with the idea that people will use it. [...]]]></description>
			<content:encoded><![CDATA[<p>A while back, I tweeted about how cool it was to have a software patch I submitted be accepted.</p>
<p>You know what&#8217;s cooler than that?</p>
<p>Realizing that someone is actually <a href="http://coderkitty.sweetperceptions.com/2009/3/27/removing-out-of-sync-error-in-acts_as_solr">using a plugin I wrote</a>.</p>
<p>I mean, working with open source, when you put something like that out there, it&#8217;s with the idea that people will use it. But having the idea is a lot different from the realization that someone you&#8217;ve never met half way around the world found something you did to be useful.</p>
<p>Edited to add: I just realized that it might not be obvious from the link, but I&#8217;m talking about the db_free_solr plugin.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.frenzicmojo.net/2009/04/the-joys-of-open-source/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Backgrounding acts_as_solr</title>
		<link>http://www.frenzicmojo.net/2009/04/backgrounding-acts-as-solr/</link>
		<comments>http://www.frenzicmojo.net/2009/04/backgrounding-acts-as-solr/#comments</comments>
		<pubDate>Mon, 06 Apr 2009 16:36:14 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[acts_as_solr]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[solr]]></category>
		<category><![CDATA[workling]]></category>

		<guid isPermaLink="false">http://www.frenzicmojo.net/?p=54</guid>
		<description><![CDATA[I know, I know. No one uses Solr anymore. Except me. And the guy that maintains acts_as_solr. And all those people who talk about it on twitter. Okay, so there are still a few people using it. This is for them.
Just a quick note on how you can improve your user&#8217;s browsing experience in an [...]]]></description>
			<content:encoded><![CDATA[<p>I know, I know. No one uses Solr anymore. Except me. And the guy that <a href="http://github.com/mattmatt/acts_as_solr/tree/master">maintains acts_as_solr</a>. And all those people who talk about it on <a href="http://search.twitter.com/search?q=solr">twitter</a>. Okay, so there are still a few people using it. This is for them.</p>
<p>Just a quick note on how you can improve your user&#8217;s browsing experience in an app that uses acts_as_solr. Our app has been using acts_as_solr for a year or more now, and we&#8217;ve generally been happy with it. Re-indexing a big table can be painful, but we don&#8217;t really end up doing that very often.</p>
<p>The one area that was still causing us some pain was the inline indexing of objects. I think the standard solution for this issue has been to defer indexing when creating/updating/deleting and have a cron job scheduled to take care of it at regular intervals. And that both works and is relatively painless. But that solution negates one of the things I like about acts_as_solr, as compared to other search solutions, which is the fact that indexing can be real time.</p>
<p>Anyway, I&#8217;m getting a little long winded, all I wanted to do here was point out something that, in retrospect, might seem obvious to others.</p>
<p>Recently, for reasons unrelated to Solr, we implemented workling and starling so that we could background some tasks that were delaying (and in some cases, timing out) our users&#8217; sessions. While I was working on it, I realized that we could use workling to background the inline solr indexing, allowing us to speed up save operations while still basically having real time indexing. Here&#8217;s how we did it (all of this assumes that you have workling installed and functioning):</p>
<p>First, we created app/workers/solr_worker.rb:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> SolrWorker <span style="color:#006600; font-weight:bold;">&amp;</span>lt; <span style="color:#6666ff; font-weight:bold;">Workling::Base</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> index_object<span style="color:#006600; font-weight:bold;">&#40;</span>options=<span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    object = options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:object_type</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">constantize</span>.<span style="color:#9900CC;">find_by_id</span><span style="color:#006600; font-weight:bold;">&#40;</span>options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:object_id</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">unless</span> object.<span style="color:#9900CC;">blank</span>?
      object.<span style="color:#9900CC;">solr_save</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> destroy_object_index<span style="color:#006600; font-weight:bold;">&#40;</span>options=<span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    object = options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:object_type</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">constantize</span>.<span style="color:#9900CC;">find_by_id</span><span style="color:#006600; font-weight:bold;">&#40;</span>options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:object_id</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">unless</span> object.<span style="color:#9900CC;">blank</span>?
      object.<span style="color:#9900CC;">solr_destroy</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Next, in vendor/plugins/acts_as_solr/lib/instance_methods.rb, we added two methods:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">def</span> async_solr_save
  SolrWorker.<span style="color:#9900CC;">async_index_object</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:object_type</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9966CC; font-weight:bold;">class</span>.<span style="color:#9900CC;">name</span>, <span style="color:#ff3333; font-weight:bold;">:object_id</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">id</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">def</span> async_solr_destroy
  SolrWorker.<span style="color:#9900CC;">async_destroy_object_index</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:object_type</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9966CC; font-weight:bold;">class</span>.<span style="color:#9900CC;">name</span>, <span style="color:#ff3333; font-weight:bold;">:object_id</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">id</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>And, finally, in vendor/plugins/acts_as_solr/lib/acts_methods.rb, we changed two lines from this:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">after_save    <span style="color:#ff3333; font-weight:bold;">:solr_save</span>
after_destroy <span style="color:#ff3333; font-weight:bold;">:solr_destroy</span></pre></div></div>

<p>To this:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">after_save    <span style="color:#ff3333; font-weight:bold;">:async_solr_save</span>
after_destroy <span style="color:#ff3333; font-weight:bold;">:async_solr_destroy</span></pre></div></div>

<p>And that&#8217;s it. This solution has been in place for a couple of weeks now, and we&#8217;ve seen a real improvement.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.frenzicmojo.net/2009/04/backgrounding-acts-as-solr/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dealing with Session Headers in soap4r</title>
		<link>http://www.frenzicmojo.net/2009/03/dealing-with-session-headers-in-soap4r/</link>
		<comments>http://www.frenzicmojo.net/2009/03/dealing-with-session-headers-in-soap4r/#comments</comments>
		<pubDate>Mon, 23 Mar 2009 17:15:31 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[soap]]></category>

		<guid isPermaLink="false">http://www.frenzicmojo.net/?p=46</guid>
		<description><![CDATA[SOAP, ugh.
Obviously, as a Rails developer, I would love it if all web services offered a REST API. It would make my life easier and drastically reduce the development curve. Sadly, though, the majority of the services I&#8217;ve had to integrate with lately only offer SOAP.
Thankfully, there&#8217;s soap4r. Hiroshi Nakamura took on the largely thankless [...]]]></description>
			<content:encoded><![CDATA[<p>SOAP, ugh.</p>
<p>Obviously, as a Rails developer, I would love it if all web services offered a REST API. It would make my life easier and drastically reduce the development curve. Sadly, though, the majority of the services I&#8217;ve had to integrate with lately only offer SOAP.</p>
<p>Thankfully, there&#8217;s soap4r. Hiroshi Nakamura took on the largely thankless job of making all of our lives easier, but creating a gem that implements SOAP for Ruby.</p>
<p>Still, as admirably as it accomplishes it&#8217;s goal, soap4r is apparently not perfect. While working through my most recent integration, I came up against a couple of issues, that don&#8217;t seem like they would be unique, so I thought I&#8217;d pass the problems and solutions along.</p>
<p>Here are the problems:</p>
<ol>
<li>The API requires the inclusion, in the SOAP header, of a session id. Include it in the body, or don&#8217;t include it at all, and you&#8217;ll get &#8220;Invalid session&#8221; errors.</li>
<li>The session expires, so that session id has to be changed.</li>
</ol>
<p>As good as SOAP4r is, it seems it&#8217;s not well equipped for these requirements (or, quite possibly, my knowledge of its usage is deficient in these areas). Without going into detail about how I tracked the issues down, I offer you the following, my solutions:</p>
<p><strong>1.</strong> This first problem seemed simple enough. The API WSDL offered a SessionHeader object, so I just assign the session id value and then use the SOAP driver&#8217;s headerhandler to include it, right?</p>
<p>Wrong.</p>
<p>Everything seems fine at first, no errors get raised on assignation. But, wait! When you actually try to execute a method via the SOAP driver, tragedy strikes:</p>
<p>NoMethodError: undefined method `on_outbound_headeritem&#8217;</p>
<p>There&#8217;s a whole stack trace that follows, leading deep into the bowels of the soap4r gem. Probably, the right thing to do would be to dig in to the code and fix it, submit a patch, yadda yadda. And, really, I&#8217;ll get to that (for both of these issues), I will. But when this came up, I needed a solution, and I needed it fast.</p>
<p>Here&#8217;s what I did:</p>
<ol>
<li>I used wsdl2ruby to pull down the API WSDL and convert it into Ruby friendly classes.</li>
<li>In the SessionHeader class, I added the on_outbound_headeritem method (your implementation will vary, depending on the definitions in the MappingRegistry file):</li>
</ol>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">  <span style="color:#9966CC; font-weight:bold;">def</span> on_outbound_headeritem<span style="color:#006600; font-weight:bold;">&#40;</span>test<span style="color:#006600; font-weight:bold;">&#41;</span>
    sobj = <span style="color:#6666ff; font-weight:bold;">SOAP::SOAPElement</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#6666ff; font-weight:bold;">XSD::QName</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;ns1&quot;</span>, <span style="color:#996600;">'SessionHeader'</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    sobj.<span style="color:#9900CC;">add</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#6666ff; font-weight:bold;">SOAP::SOAPElement</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#6666ff; font-weight:bold;">XSD::QName</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;ns1&quot;</span>, <span style="color:#996600;">&quot;session&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#0066ff; font-weight:bold;">@session</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    ::<span style="color:#6666ff; font-weight:bold;">SOAP::SOAPHeaderItem</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>sobj, <span style="color:#0000FF; font-weight:bold;">false</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>The &#8220;test&#8221; parameter in the method prototype is just a garbage variable, because soap4r expected the method to accept something. The rest is basically the translation of the SessionHeader class into a SOAP::Element, with @session being the one and only class attribute.</p>
<p><strong>2.</strong> The above solution works beautifully, except for one thing. The headerhandler in soap4r doesn&#8217;t allow for the clearing or overwriting of objects in the headerhandler. So, what happens is that after a day or so of active use, you end up with a half a dozen disparate session ids floating around in the header. I did some surfing and found this article: <a href="http://emphaticsolutions.com/2008/05/06/soap-headers-per-request-in-ruby.html">http://emphaticsolutions.com/2008/05/06/soap-headers-per-request-in-ruby.html</a>, which details a solution. Basically, the problem is easily fixed by opening up the HandlerSet object and adding a couple of methods.</p>
<p>And so, a little monkey patching in the environment.rb:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">  <span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#6666ff; font-weight:bold;">SOAP::Header::HandlerSet</span>
    <span style="color:#9966CC; font-weight:bold;">def</span> reset
      <span style="color:#0066ff; font-weight:bold;">@store</span> = <span style="color:#6666ff; font-weight:bold;">XSD::NamedElements</span>.<span style="color:#9900CC;">new</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    <span style="color:#9966CC; font-weight:bold;">def</span> set<span style="color:#006600; font-weight:bold;">&#40;</span>header<span style="color:#006600; font-weight:bold;">&#41;</span>
      reset
      add header
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Now, all you have to do is substitute this code:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">driver.<span style="color:#9900CC;">headerhandler</span> <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> session_header</pre></div></div>

<p>For this:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">driver.<span style="color:#9900CC;">headerhandler</span>.<span style="color:#9900CC;">set</span> session_header</pre></div></div>

<p>Ta Da!</p>
<p>That pretty much covers things, I think. Leave a comment or email me if you have any questions.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.frenzicmojo.net/2009/03/dealing-with-session-headers-in-soap4r/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Working with Workling</title>
		<link>http://www.frenzicmojo.net/2009/02/working-with-workling/</link>
		<comments>http://www.frenzicmojo.net/2009/02/working-with-workling/#comments</comments>
		<pubDate>Tue, 24 Feb 2009 15:10:02 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[background]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[workling]]></category>

		<guid isPermaLink="false">http://www.frenzicmojo.net/?p=12</guid>
		<description><![CDATA[Sooner or later in the life cycle of any application, there comes a time when it makes sense to explore areas where backgrounding processes might improve your Users&#8217; experience. Right now, if you&#8217;re looking to do that, the place to turn is Workling.
The obvious candidates for this kind of backgrounding include sending emails and search [...]]]></description>
			<content:encoded><![CDATA[<p>Sooner or later in the life cycle of any application, there comes a time when it makes sense to explore areas where backgrounding processes might improve your Users&#8217; experience. Right now, if you&#8217;re looking to do that, the place to turn is Workling.</p>
<p>The obvious candidates for this kind of backgrounding include sending emails and search engine indexing. In our app, though, the first performance killers to present themselves were several calls to third party APIs. Due to the limitations of one of these APIs, and some funky accounting requirements, one process can take as many as 24 separate calls (some lookups, some method calls). Now, the API response times are pretty good, but no matter how quick they may be, it&#8217;s obvious that this is going to add some inconvenient overhead to what should be a fast, responsive User session.</p>
<p>In working to background this particular process, I came up against some Workling limitations that may not be typical, or well documented. (Actually, they may be well documented, but since Google just kind of assumes that when you type &#8220;workling&#8221; you really mean &#8220;working&#8221;, it&#8217;s not always easy to find the pertinent posts.) Anyway, without further ado, some questions/problems I came across, and the answers that worked for me:</p>
<p><span style="font-weight: bold;">1. The standard how-to, startup guide has you calling the worker from the controller, but is it possible to call it from within a model instance?</span></p>
<p>This one was pretty easy to test, and the answer seems to be yes, you can. I understand it may not be the best practice, but should you find it preferable, calling the worker from within a model does not appear to present a problem. (For my purposes, it ended up making sense to call it from the controller, but I did have it working from a model at first.)</p>
<p><span style="font-weight: bold;">2. Can you pass a model as one of the options&#8217; hash values?</span></p>
<p>No. Trying this approach, you will very quickly run up against errors like &#8220;A copy of ModelName has been removed from the module tree but is still active!&#8221;</p>
<p><span style="font-weight: bold;">3. Do ActiveRecord associations work in the worker process?</span></p>
<p>That would be a no. It&#8217;s not a question I thought to ask initially, but I came up against it pretty early in the process. I could be wrong here, but in my experience, it seems like if you want to deal with a given object, you have to load it from within the worker. For me, any model methods that directly interacted with the DB failed (including simple lookups). Which made for some creative, maybe-a-little-hacky coding on my part.</p>
<p><span style="font-weight: bold;">Update:</span> It looks like the reason that ActiveRecord associations were breaking down for me wasn&#8217;t a limitation of Workling, but rather an issue with a default setting in the workling plugin. In workling/lib/workling/remote/runners/spawn_runner.rb you&#8217;ll find the following line of code:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">@@options = <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#ff3333; font-weight:bold;">:method</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#40;</span>RAILS_ENV == <span style="color:#996600;">&quot;test&quot;</span> <span style="color:#006600; font-weight:bold;">||</span> RAILS_ENV == <span style="color:#996600;">&quot;development&quot;</span> ? <span style="color:#ff3333; font-weight:bold;">:thread</span> : <span style="color:#ff3333; font-weight:bold;">:fork</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#125;</span></pre></div></div>

<p>Which is probably all well and good, so long as you&#8217;re on Rails 2.2, in which Rails is made thread safe. If, however, you&#8217;re running Rails 2.1 still, you&#8217;re going to want to change that line so it always uses :fork. Changing that solved the association related issues I had been having.</p>
<p><span style="font-weight: bold;">4. What about calling it from within a transaction?</span></p>
<p>This is potentially problematic, but not necessarily. For instance, if the worker needs to access a record that was created inside the same transaction. When it goes looking for it in the database, it may be out of luck. In retrospect, it made sense, but it didn&#8217;t occur to me until I hit the wall.</p>
<p>I think that covers all of the little gotchas I&#8217;ve come across so far. We&#8217;ve yet to deploy this latest code, or even to add Starling into the mix, so there&#8217;s always the possibility of more. If so, I&#8217;ll be sure to update this.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.frenzicmojo.net/2009/02/working-with-workling/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Learn from My mistakes #1* (Model Validations)</title>
		<link>http://www.frenzicmojo.net/2009/01/learn-from-my-mistakes-1-model-validations/</link>
		<comments>http://www.frenzicmojo.net/2009/01/learn-from-my-mistakes-1-model-validations/#comments</comments>
		<pubDate>Mon, 26 Jan 2009 23:16:32 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[activerecord]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://www.frenzicmojo.net/?p=9</guid>
		<description><![CDATA[This one is pretty obvious, but I&#8217;m going to say it anyway: Do not, I repeat, do not, rely on model validations to protect your database integrity!
My example for this is a relatively minor one, but it could easily have been much worse:
During the early development of an app I worked on, we installed acts_as_taggable_on_steroids [...]]]></description>
			<content:encoded><![CDATA[<p>This one is pretty obvious, but I&#8217;m going to say it anyway: Do not, I repeat, do not, rely on model validations to protect your database integrity!</p>
<p>My example for this is a relatively minor one, but it could easily have been much worse:</p>
<p>During the early development of an app I worked on, we installed <a href="http://github.com/mattetti/acts_as_taggable_on_steroids/tree/master">acts_as_taggable_on_steroids</a> to handle tagging. The tag model, as defined in tag.rb has this line:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">validates_uniqueness_of <span style="color:#ff3333; font-weight:bold;">:name</span></pre></div></div>

<p>Makes sense, right? Because to have duplicates of any given tag would negate the effectiveness of tagging on a whole. Well, depending on how you had things set up anyway.</p>
<p>Enter problem:</p>
<p>One feature of the app was the ability to do a bulk import of a CSV file, including tags. Any of you who have tried to do bulk imports in Rails will probably know that the first thing you do after writing a working prototype, is to factor out any and all usage of ActiveRecord, because, as beautiful and powerful as ActiveRecord is, it&#8217;s dog slow when you&#8217;re trying to import and save a few thousand records.</p>
<p>For those of you who haven&#8217;t realized where this is going, circumventing ActiveRecord means that all of those neat little model validations never fire. Which means duplicate tag records just kept on piling up, until we finally noticed it and I had to waste time writing a migration to consolidate the tags and their associations.</p>
<p>What&#8217;s the solution?</p>
<p>Database constraints!</p>
<p>Are you using validates_uniqueness_of? Add a unique index to the table!**</p>
<p><span style="font-size:85%;">* No, it&#8217;s not my first mistake, but the first in what I&#8217;m sure will be many posts featuring stupid mistakes I&#8217;ve made that you should learn from.</span><br />
<span style="font-size:85%;">** This message brought to you by the DBA in me. Rails is fantastic, but I miss me some SQL.</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.frenzicmojo.net/2009/01/learn-from-my-mistakes-1-model-validations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Thoughts on Skinny Controllers/Fat Models, Inspired by Recent Refactoring</title>
		<link>http://www.frenzicmojo.net/2009/01/thoughts-on-skinny-controllersfat-models-inspired-by-recent-refactoring/</link>
		<comments>http://www.frenzicmojo.net/2009/01/thoughts-on-skinny-controllersfat-models-inspired-by-recent-refactoring/#comments</comments>
		<pubDate>Sat, 17 Jan 2009 22:12:20 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[best practice]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://www.frenzicmojo.net/?p=7</guid>
		<description><![CDATA[The principle of fat models and skinny controllers is one that I first learned when I was initiated into the Rails community about a year and a half ago. Every single one of my fellow developers repeated it, almost like a mantra. The only problem was that no one seemed to be able to articulate [...]]]></description>
			<content:encoded><![CDATA[<p>The principle of fat models and skinny controllers is one that I first learned when I was initiated into the Rails community about a year and a half ago. Every single one of my fellow developers repeated it, almost like a mantra. The only problem was that no one seemed to be able to articulate the why of it. Don&#8217;t get me wrong, I think they knew; I just think that they had lived with it so long that the reasons had become an afterthought.</p>
<p>Being the curious sort, I needed to know the why of it. Not understanding the reasons behind the thing made it difficult for me to adopt it.  I would fill the controller and view with logic, telling myself the whole time that once I had it working I could clean it up and move it into the model.  I&#8217;m sure a lot of you are shaking your heads as you read this, because you know what I&#8217;m going to say next.  That ever elusive &#8220;clean up&#8221; session never happened.  The obvious result being that my code was functional, but ugly. I was fast up front, but when it came time to make changes, things would slow down quite a bit.  Especially if I wasn&#8217;t the developer assigned to make the change.</p>
<p>There are a lot of good articles out there about maintainability and the like.  Ultimately, though, it&#8217;s about a lot more than that.  Skinny controllers and fat models, as a principle, is the glue that holds pretty much all of the good coding practices together.</p>
<ul>
<li><span style="font-weight: bold;">TDD:</span> Controllers are a pain in the ass to test.  Ideally, all you want to have to test in controllers is that the right template is being rendered, the right action is being taken.  The minute you have to start testing assignation of values, etc&#8230; That&#8217;s the minute you stop wanting to test at all.</li>
<li><span style="font-weight: bold;">DRY:</span> It&#8217;s a lot easier to spot duplicate code if it&#8217;s all in the same place, and with fat models that&#8217;s much more likely to be the case. Also, if a function you need is sitting at the bottom of some controller, it starts to get a lot easier to just copy and paste it, rather than trying to share it. </li>
<li><span style="font-weight: bold;">Maintainability:</span> The previous 2 points kind of play into this one. If you have good test coverage, and don&#8217;t have to worry so much about changes having unforeseen (and untraceable) effects in other parts of your app, you&#8217;ll be a lot less hesitant about refactoring your code. If your code is DRY, you won&#8217;t have to worry so much that the change you make here, might not show up there.</li>
<li><span style="font-weight: bold;">Readability:</span> Let&#8217;s face it, the code that&#8217;s easiest to read, isn&#8217;t DRY.  It&#8217;s linear, it&#8217;s all in one place, it doesn&#8217;t make function calls that you have to hunt down (&#8221;Is that function in the helper? No, I think it&#8217;s in a lib file. No, wait, maybe it&#8217;s in this included module&#8230;&#8221;).  The problem is, that this code also isn&#8217;t maintainable at all. With the kind of setup I just described, one little text change is likely to require a dozen different files to be altered. So, short of that kind of readability, you want to have everything be easily locatable.  Sure, an IDE can help with that, but for those of us using TextMate and vim, we have to resort to keeping things as concise as possible. And DRY does help with that. As does keeping as much of the logic in the model (i.e. in one place) as possible.
</li>
<li><span style="font-weight: bold;">Design:</span> Skinny controllers and fat models&#8230; You know what&#8217;s left out of that equation? The views. One of the nice side effects of keeping as much logic as possible in the model is that it also stays out of the view. Once you start filling the controller with unnecessary code, it&#8217;s really easy to start doing a bunch of if and case statements in the view. (&#8221;Oh, and we need this record, too, but only in this one little spot that may not even be rendered&#8230; I&#8217;ll just put the Class.find here at the top of the partial.&#8221; And so it goes.) The more you can keep code out of your view, the easier it will be for your designer to go in and integrate his or her newly chopped comp.</li>
</ul>
<p> All of it is made easier by sticking to the skinny controller/fat model ideal.  And, conversely, all of it is a lot easier to allow to fall by the wayside if you don&#8217;t.</p>
<p>Of course, I realize I&#8217;m not really saying anything new here, or maybe I&#8217;m just not saying anything that most rails developers don&#8217;t already know.  But sometimes it helps to say it out loud, even if you&#8217;re repeating yourself.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.frenzicmojo.net/2009/01/thoughts-on-skinny-controllersfat-models-inspired-by-recent-refactoring/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Problems with VMWare Fusion</title>
		<link>http://www.frenzicmojo.net/2009/01/problems-with-vmware-fusion/</link>
		<comments>http://www.frenzicmojo.net/2009/01/problems-with-vmware-fusion/#comments</comments>
		<pubDate>Sat, 17 Jan 2009 20:59:17 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[fusion]]></category>
		<category><![CDATA[vmware]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://www.frenzicmojo.net/?p=5</guid>
		<description><![CDATA[I&#8217;ve noticed that my Windows XP image in VMWare occasionally drops its shared connection.  I&#8217;ll be plugging away, happily checking cross-browser compatibility (okay, that&#8217;s a lie, I&#8217;m miserable when I check cross-browser compatibility, which only makes it worse when it stops working) when all of a sudden, nothing is sudden anymore.
Pages will either not [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve noticed that my Windows XP image in VMWare occasionally drops its shared connection.  I&#8217;ll be plugging away, happily checking cross-browser compatibility (okay, that&#8217;s a lie, I&#8217;m miserable when I check cross-browser compatibility, which only makes it worse when it stops working) when all of a sudden, nothing is sudden anymore.</p>
<p>Pages will either not load at all or load so slowly that I&#8217;d almost prefer to get a &#8220;Page cannot be displayed&#8221; error.  Usually this happens for a while before it occurs to me that the connection has dropped.  Then I have to go find <a href="http://timesinker.blogspot.com/2007/09/switch-off-vmware-fusion-services-in.html">this post</a>, which helpfully provides the terminal command that will restart the connection:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span>  <span style="color: #ff0000;">&quot;/Library/Application Support/VMware Fusion/boot.sh&quot;</span> <span style="color: #660033;">--restart</span></pre></div></div>

<p>All of a sudden, the connection is whip-quick (well, you know, as whip-quick as IE gets, anyway). Problem solved.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.frenzicmojo.net/2009/01/problems-with-vmware-fusion/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting Around AR</title>
		<link>http://www.frenzicmojo.net/2008/04/getting-around-ar/</link>
		<comments>http://www.frenzicmojo.net/2008/04/getting-around-ar/#comments</comments>
		<pubDate>Mon, 14 Apr 2008 15:04:58 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[activerecord]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.frenzicmojo.net/?p=3</guid>
		<description><![CDATA[So, this was a pain: I spent about 2 hours this weekend trying to find an easy way to execute a SQL select statement while circumventing the ActiveRecord model. After scouring the web and some old code, I found this:

Model.connection.select_rows&#40;sql&#41;

It returns an array of arrays, each inner array representing a record of data. Easy to [...]]]></description>
			<content:encoded><![CDATA[<p>So, this was a pain: I spent about 2 hours this weekend trying to find an easy way to execute a SQL select statement while circumventing the ActiveRecord model. After scouring the web and some old code, I found this:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">Model.<span style="color:#9900CC;">connection</span>.<span style="color:#9900CC;">select_rows</span><span style="color:#006600; font-weight:bold;">&#40;</span>sql<span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>It returns an array of arrays, each inner array representing a record of data. Easy to do, and the results are easy to deal with.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.frenzicmojo.net/2008/04/getting-around-ar/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
