<?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>Snow Giraffe Tech &#187; Ruby on Rails</title>
	<atom:link href="http://www.snowgiraffe.com/tech/category/ruby-on-rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.snowgiraffe.com/tech</link>
	<description>rails, rubies, and sometimes dolphins</description>
	<lastBuildDate>Mon, 07 Jun 2010 14:36:05 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Analyze This!: Now with Zombies</title>
		<link>http://www.snowgiraffe.com/tech/626/analyze-this-now-with-zombies/</link>
		<comments>http://www.snowgiraffe.com/tech/626/analyze-this-now-with-zombies/#comments</comments>
		<pubDate>Mon, 07 Jun 2010 14:36:05 +0000</pubDate>
		<dc:creator>blythe</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://www.snowgiraffe.com/tech/?p=626</guid>
		<description><![CDATA[A new house, a new job, and a new knee made of zombie parts take me to Baltimore to present Analyze This!]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m headed to Baltimore today to speak at <a href="http://en.oreilly.com/rails2010/public/schedule/detail/14166">Railsconf</a> and this year I come with a new sweet house, a new job (back to freelance yay!) and a new knee made of dead people. Well ok, only the exploded ski knee replacement ACL part is made of zombies because I <em>think</em> they cleared most of them out of the new house before I moved in.</p>
<p>I&#8217;m actually pretty excited to talk this year because after all the aforementioned ski accident surgery business, I didn&#8217;t think I could make it to the left coast let alone walk(ish) and get to present a really awesome story. Huh? you say. Aren&#8217;t you talking about, ah hem, analytics? Why yes, and its Ms. <a href="http://en.oreilly.com/rails2010/public/schedule/detail/14166">Analyze  This!</a> to you, actually. I&#8217;m going to take this presentation back through time to the early days of digital page view counters (come on, you never hit refresh 6 times so you could be visitor number 1,000&#8230; nirvana was playing on radio?) through a couple of  BIG SCALED rails analytics implementations and all the way to today&#8217;s brave new world of actionable analytics where we care about retweets and bounce rate instead of how many (not guest, don&#8217;t count the guests!) users you had last Thursday. Oh yeah and of course there is code, glorious wonderful code! Here&#8217;s a preview and/or challenge. What are 6 reasons you want to avoid this:</p>
<pre class="ruby"><span class="ident">after_filter</span> <span class="keyword">do</span> <span class="punct">|</span><span class="ident">controller</span><span class="punct">|</span>
  <span class="constant">Hit</span><span class="punct">.</span><span class="ident">create!</span><span class="punct">(</span>
    <span class="symbol">:ip_address</span> <span class="punct">=&gt;</span> <span class="ident">request</span><span class="punct">.</span><span class="ident">ip_address</span><span class="punct">,</span>
    <span class="symbol">:headers</span>    <span class="punct">=&gt;</span> <span class="ident">request</span><span class="punct">.</span><span class="ident">headers</span>
  <span class="punct">)</span>
<span class="keyword">end

</span></pre>
<p>Hope to see you at the function! Thursday 10:45am 6/10/2010 Ballroom IV</p>
]]></content:encoded>
			<wfw:commentRss>http://www.snowgiraffe.com/tech/626/analyze-this-now-with-zombies/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Rails Application Health Monitor</title>
		<link>http://www.snowgiraffe.com/tech/599/health-monitor/</link>
		<comments>http://www.snowgiraffe.com/tech/599/health-monitor/#comments</comments>
		<pubDate>Mon, 14 Dec 2009 02:43:54 +0000</pubDate>
		<dc:creator>blythe</dc:creator>
				<category><![CDATA[Plugins]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[gems]]></category>
		<category><![CDATA[monitor rails health]]></category>

		<guid isPermaLink="false">http://www.snowgiraffe.com/tech/?p=599</guid>
		<description><![CDATA[The health monitor gem allows you to monitor your rails application through a single controller action. In addition to built in database and server environment checks, health monitor allows you to quickly add your customized health checks to the mix.]]></description>
			<content:encoded><![CDATA[<p><img class="alignright" title="hot-thermometer" src="http://www.snowgiraffe.com/tech/wp-content/uploads/2009/12/hot-thermometer-172x300.gif" alt="hot-thermometer" width="109" height="191" /><br />
Most rails applications have many additional moving parts of which the health cannot be assessed with simply pinging the (hopefully page cached) homepage</p>
<p>For example,</p>
<ul>
<li>Is Email is sent successfully?</li>
<li>Is the SMS gateway alive and you bought sufficient credits?</li>
<li>All database connections are alive? Backgroundrb down again?</li>
<li>The cloud computing setup jacked the imagemagick? Again?</li>
<li>You are running out of disk space and there are no more file descriptors for your</li>
<li>The git SHA and version is correct</li>
<p style="text-align: center;"><img class="size-medium wp-image-604 aligncenter" title="Screen shot 2009-12-06 at 12.29.53 AM" src="http://www.snowgiraffe.com/tech/wp-content/uploads/2009/12/Screen-shot-2009-12-06-at-12.29.53-AM-300x100.png" alt="Screen shot 2009-12-06 at 12.29.53 AM" width="300" height="100" /></p>
</ul>
<p><a href="http://github.com/blythedunham/health_monitor" target="_blank">Health Monitor</a> adds a single controller action to generate an html, js, or xml report with details of <strong>all</strong> your custom defined health checks. An error response code (500 server error) indicates failure when any monitored feature fails or exceeds the custom timeout definition. <a href="http://www.snowgiraffe.com/tech/599/health-monitor/" target="_blank">Health monitor</a> is easier to setup than custom server side cron tasks and adds the advantage of exercising more code since everything from your load balancer to nginx to mongrels must be happily shoving rubies around to get that 200 oh boy success message. So ping away, grab a beer and know that hey, you might be too drunk but at least you will know your application is sick before your clients do.</p>
<h2><strong>Install</strong></h2>
<pre>sudo gem install health_monitor --source=http://gemcutter.org

config.gem :health_monitor, :source =&gt; http://gemcutter.org</pre>
<h2><strong>Create a the health monitor controller<br />
</strong></h2>
<pre>script/generate health_monitor</pre>
<h2><strong>Add your customizations</strong></h2>
<pre class="ruby">  <span class="keyword">class </span><span class="class">HealthMonitorController</span> <span class="punct">&lt;</span> <span class="constant">ApplicationController</span>
    <span class="ident">acts_as_health_monitor</span>

    <span class="comment">#More examples available at http://github.com/blythedunham/health_monitor</span>
    <span class="comment">#Built in checks</span>
    <span class="ident">monitor_health</span> <span class="symbol">:schema_check</span><span class="punct">,</span> <span class="symbol">:database_check</span><span class="punct">,</span> <span class="symbol">:ey_agent_check</span>

    <span class="comment">#monitor specified process</span>
    <span class="ident">monitor_process</span> <span class="symbol">:monit</span> 

    <span class="comment"># Custom monitor task</span>
    <span class="ident">monitor_health</span> <span class="symbol">:email</span><span class="punct">,</span> <span class="symbol">:description</span> <span class="punct">=&gt;</span> <span class="punct">'</span><span class="string">send an email</span><span class="punct">'</span> <span class="keyword">do</span> <span class="punct">|</span><span class="ident">controller</span><span class="punct">|</span>
      <span class="constant">ActionMailer</span><span class="punct">::</span><span class="constant">Base</span><span class="punct">.</span><span class="ident">deliver_my_mail</span><span class="punct">('</span><span class="string">blah</span><span class="punct">')</span>
    <span class="keyword">end</span>
  <span class="keyword">end
</span></pre>
<h2>Routes</h2>
<p>Routes are automatically generated:<br />
http://localhost:3000/health_monitor<br />
http://localhost:3000/health_monitor.js</p>
<p>Monitor specific tasks or skip tasks with the parameters <strong>skip</strong> and <strong>only</strong><br />
http://localhost:3000/health_monitor?only=schema_check,database_check<br />
http://localhost:3000/health_monitor?skip=email,database_check</p>
]]></content:encoded>
			<wfw:commentRss>http://www.snowgiraffe.com/tech/599/health-monitor/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Hey is that you database crying?</title>
		<link>http://www.snowgiraffe.com/tech/567/hey-is-that-you-database-crying/</link>
		<comments>http://www.snowgiraffe.com/tech/567/hey-is-that-you-database-crying/#comments</comments>
		<pubDate>Mon, 05 Oct 2009 21:16:22 +0000</pubDate>
		<dc:creator>blythe</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://www.snowgiraffe.com/tech/?p=567</guid>
		<description><![CDATA[Download  crying databases from Aloha Rails Conf.

]]></description>
			<content:encoded><![CDATA[<p>Download  <a href="http://snowgiraffe.com/downloads/presentations/hey_is_that_your_database_crying.pdf">crying databases </a>from <a href="http://alohaonrails.com">Aloha Rails Conf</a>.<br />
<img class="alignleft size-thumbnail wp-image-566" title="cryingwhileeating" src="http://www.snowgiraffe.com/tech/wp-content/uploads/2009/10/cryingwhileeating-150x150.jpg" alt="cryingwhileeating" width="150" height="150" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.snowgiraffe.com/tech/567/hey-is-that-you-database-crying/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Hey&#8230; is that your surfboard crying?</title>
		<link>http://www.snowgiraffe.com/tech/541/hey-is-that-your-surfboard-crying/</link>
		<comments>http://www.snowgiraffe.com/tech/541/hey-is-that-your-surfboard-crying/#comments</comments>
		<pubDate>Tue, 25 Aug 2009 16:26:53 +0000</pubDate>
		<dc:creator>blythe</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[alohaonrails]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[Hawaii]]></category>

		<guid isPermaLink="false">http://www.snowgiraffe.com/tech/?p=541</guid>
		<description><![CDATA[Rails is at Hawaii 10/5 OMG]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.alohaonrails.com/sessions/#hey-is-that-your-database-crying"><img class="alignright size-full wp-image-131" title="I Am Speaking At Aloha On Rails, The Hawaii Ruby on Rails Conference" src="http://www.alohaonrails.com/wp-content/uploads/2009/05/aor_spkr.jpg" alt="I Am Speaking At Aloha On Rails, The Hawaii Ruby on Rails Conference" width="154" height="218" /></a>My snowboard is jealous. I am going to Hawaii to ride surfboards, dive with sharks, jump off cliffs and present <a href="http://www.alohaonrails.com/sessions/#hey-is-that-your-database-crying">Hey&#8230;. is that your database crying?</a> at the <a href="http://alohaonrails.com">alohaonrails</a> conference. There are some really great talks lined up about Map Reduce/Pig/Hadoop, Rails 3 and general ruby shoving. And seriously, who doesn&#8217;t want to be in Waikiki.</p>
<p>Hawaii 10-5 O (M G)!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.snowgiraffe.com/tech/541/hey-is-that-your-surfboard-crying/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Delectable plugin treats for the ruby shovers</title>
		<link>http://www.snowgiraffe.com/tech/545/delectable-plugin-treats-for-the-ruby-shovers/</link>
		<comments>http://www.snowgiraffe.com/tech/545/delectable-plugin-treats-for-the-ruby-shovers/#comments</comments>
		<pubDate>Tue, 25 Aug 2009 20:45:37 +0000</pubDate>
		<dc:creator>blythe</dc:creator>
				<category><![CDATA[ActiveRecord]]></category>
		<category><![CDATA[Caching]]></category>
		<category><![CDATA[Plugins]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[ActiveRecord Dumper]]></category>
		<category><![CDATA[AR Dumper]]></category>
		<category><![CDATA[Asset Tag Extensions]]></category>
		<category><![CDATA[Google Base4r]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[Ruby Prof]]></category>
		<category><![CDATA[Ruby Prof Request Filters]]></category>

		<guid isPermaLink="false">http://www.snowgiraffe.com/tech/?p=545</guid>
		<description><![CDATA[Been a long time. shouldn&#8217;t of left ya without a dope plugin to step to. meh. But for reals, I&#8217;ve been working way too much. Here&#8217;s a tasty sampler of some new and revived github projects:

ActiveRecord Dumper
Asset Tag Extensions
Ruby Prof Request Filters
Google Base4r extensions

ActiveRecord Dumper
script/plugin install http://github.com/blythedunham/ar_dumper
Dumper. I barely know her! I wrote this ages [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_555" class="wp-caption alignright" style="width: 160px"><img class="size-thumbnail wp-image-555  " style="margin-left: 5px;" title="candy_sampler" src="http://www.snowgiraffe.com/tech/wp-content/uploads/2009/08/candy_sampler-150x150.jpg" alt="Candy raver plugin funtime!" width="150" height="150" /><p class="wp-caption-text">Delicatable treats for the rubies.</p></div>
<p>Been a long time. shouldn&#8217;t of left ya without a dope plugin to step to. meh. But for reals, I&#8217;ve been working way too much. Here&#8217;s a tasty sampler of some new and revived github projects:</p>
<ul>
<li><a href="http://github.com/blythedunham/asset_tag_extensions">ActiveRecord Dumper</a></li>
<li><a href="http://github.com/blythedunham/asset_tag_extensions">Asset Tag Extensions</a></li>
<li><a href="http://github.com/blythedunham/ruby_prof_request_filters/">Ruby Prof Request Filters</a></li>
<li><a href="http://github.com/blythedunham/base4r/">Google Base4r extensions</a></li>
</ul>
<h2><a href="http://github.com/blythedunham/asset_tag_extensions">ActiveRecord Dumper</a></h2>
<pre>script/plugin install http://github.com/blythedunham/ar_dumper</pre>
<p>Dumper. I barely know her! I wrote this ages ago back in the Rails 1 dot 0h(mg) daze, but still works like a charm.</p>
<p>Easily export records to csv, yaml, or xml using the <tt>:find</tt> options, or <span style="color: #ff0000;">(new) </span>specify an array of activerecords with the <tt>:records</tt> option. AR Dumper dumps to strings or files with a paginated option, and it supports full customization of displayed headers and content with options such as  <tt> <img src='http://www.snowgiraffe.com/tech/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> nly, :export, :procs, :methods</tt></p>
<pre class="ruby"><span class="constant">Book</span><span class="punct">.</span><span class="ident">dumper</span> <span class="symbol">:yml</span><span class="punct">,</span> <span class="symbol">:find</span> <span class="punct">=&gt;</span> <span class="punct">{</span><span class="symbol">:conditions</span> <span class="punct">=&gt;</span> <span class="punct">['</span><span class="string">author_name like ?</span><span class="punct">',</span> <span class="punct">'</span><span class="string">snowgiraffe</span><span class="punct">']</span> <span class="punct">}</span>

<span class="constant">Book</span><span class="punct">.</span><span class="ident">dumper</span> <span class="symbol">:csv</span><span class="punct">,</span> <span class="symbol"> <img src='http://www.snowgiraffe.com/tech/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> nly</span> <span class="punct">=&gt;</span> <span class="punct">[</span><span class="symbol">:author_name</span><span class="punct">,</span> <span class="symbol">:title</span><span class="punct">],</span> <span class="symbol">:records</span> <span class="punct">=&gt;</span> <span class="attribute">@my_books</span></pre>
<p><span class="constant"><br />
</span></p>
<h2><a href="http://github.com/blythedunham/asset_tag_extensions">Asset Tag Extensions</a></h2>
<pre>script/plugin install git://github.com/blythedunham/javascript_tag_extensions</pre>
<p><img class="alignleft size-thumbnail wp-image-556" title="nuts_sampler" src="http://www.snowgiraffe.com/tech/wp-content/uploads/2009/08/nuts_sampler-150x150.jpg" alt="nuts_sampler" width="136" height="136" />Your high performance web site client loading slowly? In addition to combining asset files, one of the best ways to improve client load speed is to move the javascript files and inline script tags to <a href="http://developer.yahoo.com/performance/rules.html#page-nav">the bottom of the page</a>. Even better, execute inline javascript after the document loads.  To load files at the bottom of the page use the</p>
<pre class="ruby"><span class="ident">include_javascript_tag</span> <span class="punct">'</span><span class="string">myjsfile</span><span class="punct">',</span> <span class="symbol">:defer</span> <span class="punct">=&gt;</span> <span class="constant">true</span></pre>
<p>Similarly, replacing calls to <tt> javascript_tag</tt> with Asset Tag Extension&#8217;s  <tt>inline_javascript</tt> renders the script at the bottom of the page. Use the <tt> <img src='http://www.snowgiraffe.com/tech/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> n_load =&gt; true</tt> functionality use JQuery OnLoad functionality.</p>
<pre class="ruby">  <span class="punct">&lt;%</span>  <span class="ident">inline_javascript</span> <span class="symbol"> <img src='http://www.snowgiraffe.com/tech/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> n_load</span> <span class="punct">=&gt;</span> <span class="constant">true</span> <span class="keyword">do</span> <span class="punct">%&gt;</span><span class="string">
    alert("I love grapes");</span><span class="punct">
  &lt;%</span> end <span class="punct">%&gt;
</span></pre>
<h2><a href="http://github.com/blythedunham/ruby_prof_request_filters/">Ruby Prof Request Filters</a></h2>
<pre>script/plugin install http://github.com/blythedunham/ruby_prof_request_filters</pre>
<p>Need to instantly profile a page? Output <a href="http://ruby-prof.rubyforge.org/">ruby prof</a> results to your browser by adding the following params to the url: <tt>ruby_prof=true</tt> Flat graphs, html graph, whatever you need, this little tool comes in handy when your solving big problems.</p>
<h2><a href="http://github.com/blythedunham/base4r/">Google Base: Base4r</a></h2>
<p>I did some work on Dan Dukeson&#8217;s <a href="http://code.google.com/apis/base/">Google Base API </a>For Ruby. Add, modify and delete items from Google Base (formerly Froogle) with Ruby.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.snowgiraffe.com/tech/545/delectable-plugin-treats-for-the-ruby-shovers/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Logging with Rake</title>
		<link>http://www.snowgiraffe.com/tech/538/logging-with-rake/</link>
		<comments>http://www.snowgiraffe.com/tech/538/logging-with-rake/#comments</comments>
		<pubDate>Wed, 08 Jul 2009 20:02:22 +0000</pubDate>
		<dc:creator>blythe</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[rake task logger]]></category>

		<guid isPermaLink="false">http://www.snowgiraffe.com/tech/?p=538</guid>
		<description><![CDATA[Snippet to log ActiveRecord output to stdout at specified log level for Rake tasks.]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve gotten a little tired of failing rake tasks that don&#8217;t give me enough diagnostic information with just the <span class="inline_code">&#8211;trace</span> option. Here&#8217;s a little snippet to redirect the ActiveRecord (and SQL in debug mode) output to stdout. Then pipe it into a file for safe keeping.</p>
<pre>rake mytask LOG=DEBUG &gt; mytask.out</pre>
<pre class="ruby"><span class="keyword">
def </span><span class="method">set_logger</span>
  <span class="comment">#configure ActiveRecord to log to Stdout</span>
  <span class="keyword">if</span> <span class="punct">(</span><span class="ident">log</span> <span class="punct">=</span> <span class="punct">(</span><span class="constant">ENV</span><span class="punct">['</span><span class="string">LOG</span><span class="punct">']||</span><span class="constant">ENV</span><span class="punct">['</span><span class="string">log</span><span class="punct">']))</span> <span class="punct">&amp;&amp;</span> <span class="ident">log</span><span class="punct">.</span><span class="ident">to_s</span><span class="punct">.</span><span class="ident">downcase</span> <span class="punct">!=</span> <span class="punct">'</span><span class="string">false</span><span class="punct">'</span>
    <span class="constant">ActiveRecord</span><span class="punct">::</span><span class="constant">Base</span><span class="punct">.</span><span class="ident">logger</span> <span class="punct">=</span> <span class="constant">Logger</span><span class="punct">.</span><span class="ident">new</span><span class="punct">(</span><span class="constant">STDOUT</span><span class="punct">)</span>
    <span class="constant">ActiveRecord</span><span class="punct">::</span><span class="constant">Base</span><span class="punct">.</span><span class="ident">logger</span><span class="punct">.</span><span class="ident">level</span> <span class="punct">=</span> <span class="keyword">begin</span>
      <span class="ident">log</span> <span class="punct">=~</span> <span class="punct">/</span><span class="regex">^<span class="escape">\d</span>*$</span><span class="punct">/</span> <span class="punct">?</span> <span class="ident">log</span><span class="punct">.</span><span class="ident">to_i</span> <span class="punct">:</span> <span class="constant">Logger</span><span class="punct">.</span><span class="ident">const_get</span><span class="punct">(</span><span class="ident">log</span><span class="punct">.</span><span class="ident">upcase</span><span class="punct">)</span>
    <span class="keyword">rescue</span>
      <span class="constant">Logger</span><span class="punct">::</span><span class="constant">INFO</span>
    <span class="keyword">end</span>
    <span class="ident">puts</span> <span class="punct">"</span><span class="string">ActiveRecord to STDOUT level <span class="expr">#{ActiveRecord::Base.logger.level}</span></span><span class="punct">"</span>
    <span class="constant">ActiveRecord</span><span class="punct">::</span><span class="constant">Base</span><span class="punct">.</span><span class="ident">connection</span><span class="punct">.</span><span class="ident">instance_variable_set</span><span class="punct">('</span><span class="string">@logger</span><span class="punct">',</span> <span class="constant">ActiveRecord</span><span class="punct">::</span><span class="constant">Base</span><span class="punct">.</span><span class="ident">logger</span><span class="punct">)</span>
    <span class="constant">Paperclip</span><span class="punct">.</span><span class="ident">options</span><span class="punct">[</span><span class="symbol">:log</span><span class="punct">]</span> <span class="punct">=</span> <span class="constant">true</span>
  <span class="keyword">end</span>
<span class="keyword">end</span></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.snowgiraffe.com/tech/538/logging-with-rake/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>ar_test_runner: Run the ActiveRecord unit test suite with your modifications</title>
		<link>http://www.snowgiraffe.com/tech/507/ar_test_runner-run-activerecord-unit-tests-with-your-code/</link>
		<comments>http://www.snowgiraffe.com/tech/507/ar_test_runner-run-activerecord-unit-tests-with-your-code/#comments</comments>
		<pubDate>Tue, 12 May 2009 19:43:24 +0000</pubDate>
		<dc:creator>blythe</dc:creator>
				<category><![CDATA[ActiveRecord]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[ar-extensions]]></category>
		<category><![CDATA[ar_test_runner]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[regression test]]></category>
		<category><![CDATA[test]]></category>

		<guid isPermaLink="false">http://www.snowgiraffe.com/tech/?p=507</guid>
		<description><![CDATA[ar_test_runner provides a rake task to run the ActiveRecord core test suites with your plugins or files loaded. Make sure ActiveRecord tasks pass with your enhancements.]]></description>
			<content:encoded><![CDATA[<p><a style="padding-right: 5px; padding-bottom:15px;" href="http://www.flickr.com/photos/10407019@N08/868905183/"><img class="size-medium wp-image-517 alignleft" title="ghostrunners" src="http://www.snowgiraffe.com/tech/wp-content/uploads/2009/05/ghostrunners-300x199.jpg" alt="Run ActiveRecord regression tests with your code loaded" width="216" height="143" /></a>If you write plugins or code to enhance ActiveRecord functionality, its a really good idea to run the ActiveRecord core test suite with your cool additions loaded. After working on <a href="http://github.com/zdennis/ar-extensions">ar-extensions</a>, I liked the idea of running the core tests along with the plugin specific tests.  However, I soon grew tired of coding the same Rakefile for each of my eleventy billion AR plugins. Not DRY. Not fun. Not a unicorn party.</p>
<p>Thus was born, <a href="http://github.com/blythedunham/ar_test_runner">ar_test_runner</a>, a convenient plugin with a rake task to run the ActiveRecord test suites with your  code/gem/plugin load. You even can choose the ActiveRecord version and database.</p>
<h3>Install</h3>
<pre>  gem sources -a http://gems.github.com
  sudo gem install blythedunham-ar_test_runner</pre>
<h3>Run ar_test_runner</h3>
<p>Run all plugins and lib files against sqlite for app version</p>
<pre>ar_test_runner DB=sqlite</pre>
<p>Test 2.2.2 with <a href="http://github.com/blythedunham/rails"><span class="inlineCode">rails_devs_for_data_integrity</span></a> plugin loaded on mysql</p>
<pre>ar_test_runner PLUGIN=rails_devs_for_data_integrity AR_DIR=/Library/Ruby/Gems/1.8/gems/activerecord-2.2.2</pre>
<h3>Rake Tasks</h3>
<p>ar_test_runner works as a rake task, if installed as a plugin or by adding <span class="inlineCode"> require &#8220;ar_test_runner&#8221;</span> to the application&#8217;s Rakefile. The following example tests the applications default version of ActiveRecord with the files <span class="inlineCode">RAILS_ROOT/lib/my_file.rb</span> and <span class="inlineCode">RAILS_ROOT/lib/my_other_file.rb loaded</span></p>
<pre>rake test:activerecord:mysql FILE=lib/my_file.rb,lib/my_other_file.rb</pre>
<h3>Customize</h3>
<p>To specify (or skip)  gems, files, dirs, and plugins ot load or build custom runs see the documentation at <a href="http://github.com/blythedunham/ar_test_runner">ar_test_runner</a> .</p>
]]></content:encoded>
			<wfw:commentRss>http://www.snowgiraffe.com/tech/507/ar_test_runner-run-activerecord-unit-tests-with-your-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RailsConf 2009: powered by OMG UNICORNS!!!!</title>
		<link>http://www.snowgiraffe.com/tech/483/railsconf-powered-by-unicorns/</link>
		<comments>http://www.snowgiraffe.com/tech/483/railsconf-powered-by-unicorns/#comments</comments>
		<pubDate>Mon, 11 May 2009 17:19:54 +0000</pubDate>
		<dc:creator>blythe</dc:creator>
				<category><![CDATA[Giraffe Mutterings]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[acts_as_unicorn]]></category>
		<category><![CDATA[RailsConf]]></category>
		<category><![CDATA[unicorns]]></category>

		<guid isPermaLink="false">http://www.snowgiraffe.com/tech/?p=483</guid>
		<description><![CDATA[The big takeaway from this years RailsConf is: everyone loves UNICORNS! Learn how to cornify your site like a rockstar.]]></description>
			<content:encoded><![CDATA[<div id="attachment_492" class="wp-caption alignright" style="width: 220px"><img class="size-medium wp-image-492" title="unicorn_narwhal" src="http://www.snowgiraffe.com/tech/wp-content/uploads/2009/05/unicorn_narwhal-300x297.jpg" alt="OMG Unicorns at RailsConf!" width="210" height="208" /><p class="wp-caption-text">OMG Unicorns at RailsConf!</p></div>
<p>The over all theme of this years RailsConf was: <a onclick="cornify_add();return false;" href="http://www.cornify.com">UNICORNS (click me!)</a> I mean, yeah Rails 3 is rad, racks and clouds are great and we are scaling better now, but now with the power of<a onclick="cornify_add();return false;" href="http://www.cornify.com"> OMG UNICORNS!</a> The <a href="http://en.oreilly.com/rails2009/public/schedule/detail/7592">Phusion guys</a> even made a Unicorn edition of <a href="http://www.rubyinside.com/rubystein-wolfenstein-3d-recreated-in-ruby-1751.html">Rubystein</a> to prove how fast ruby can go. Wow! I really enjoyed Chris Wanstrath&#8217;s  <a href="http://railsconf.blip.tv/file/2086330/">keynote</a> on how you could blog your to your way rockstarness (but its better to be a good coder), but Chris, you forgot to mention that adding<a onclick="cornify_add();return false;" href="http://www.cornify.com"> unicorns</a> makes a blog at least 83.45% more successful.</p>
<p>Back when I was a little girl, I dreamed of a future with flying Jetson like hovercraft and space travel. Yet this quite frankly, this future sucks. Instead of awesome, everyone just argues over the best way to round button corners. But now&#8230;. <a onclick="cornify_add();return false;" href="http://www.cornify.com"> OMG UNICORNS!</a>I don&#8217;t feel so sad anymore. As I mentioned in my <a href="http://www.snowgiraffe.com/tech/475/railsconf-2009-integrating-sms-with-your-rails-application/">SMS talk</a>, I even upgraded my database to run on flowers so the <a onclick="cornify_add();return false;" href="http://www.cornify.com">unicorns</a> will come and play! Thanks RailsConf!</p>
<p>There is no need to argue about the best way to add <a onclick="cornify_add();return false;" href="http://www.cornify.com">unicorns</a> to your rails app. Simply <a href="http://cornify.com">cornify</a> it up with the new <a href="http://github.com/blythedunham/acts_as_unicorn">acts_as_unicorn</a> plugin. <a href="http://github.com/blythedunham/acts_as_unicorn">Acts_as_unicorn</a> gives you control to decide which actions are <a onclick="cornify_add();return false;" href="http://www.cornify.com">unicorn</a> worthy.</p>
<pre>script/plugin install git://github.com/blythedunham/acts_as_unicorn</pre>
<p>Add <a onclick="cornify_add();return false;" href="http://www.cornify.com">unicorns</a> to your pages!</p>
<pre class="ruby"><span class="keyword">class </span><span class="class">UnicornController</span> <span class="punct">&lt;</span> <span class="constant">ApplicationController</span>
  <span class="ident">acts_as_unicorn</span> <span class="punct">'</span><span class="string">OMG UNICORNS</span><span class="punct">!',</span> <span class="symbol">:except</span> <span class="punct">=&gt;</span> <span class="symbol">:stupid_not_unicorn_action</span>
<span class="keyword">end</span></pre>
<h3>Try it: <a onclick="cornify_add();return false;" href="http://www.cornify.com"> OMG UNICORNS!</a></h3>
]]></content:encoded>
			<wfw:commentRss>http://www.snowgiraffe.com/tech/483/railsconf-powered-by-unicorns/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>RailsConf 2009: Integrating SMS with your Rails Application</title>
		<link>http://www.snowgiraffe.com/tech/475/railsconf-2009-integrating-sms-with-your-rails-application/</link>
		<comments>http://www.snowgiraffe.com/tech/475/railsconf-2009-integrating-sms-with-your-rails-application/#comments</comments>
		<pubDate>Thu, 07 May 2009 18:19:59 +0000</pubDate>
		<dc:creator>blythe</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[ar-extensions]]></category>
		<category><![CDATA[RailsConf]]></category>
		<category><![CDATA[SMS]]></category>
		<category><![CDATA[sms on rails]]></category>

		<guid isPermaLink="false">http://www.snowgiraffe.com/tech/?p=475</guid>
		<description><![CDATA[This presentation includes some good tips on how to integrate with sms, especially for Rails applications. The SMS on Rails engine plugin demo steps are included.]]></description>
			<content:encoded><![CDATA[<div id="__ss_1402467" style="width: 425px; text-align: left;"><a style="font:14px Helvetica,Arial,Sans-serif;display:block;margin:12px 0 3px 0;text-decoration:underline;" title="RailsConf2009 Integrating SMS with your Rails App" href="http://www.slideshare.net/snowgiraffe/railsconf2009-integrating-sms-with-your-rails-app?type=presentation">RailsConf2009 Integrating SMS with your Rails App</a><object width="425" height="355" data="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=railsconf2009sms-090507162144-phpapp01&amp;stripped_title=railsconf2009-integrating-sms-with-your-rails-app" type="application/x-shockwave-flash"><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always" /><param name="src" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=railsconf2009sms-090507162144-phpapp01&amp;stripped_title=railsconf2009-integrating-sms-with-your-rails-app" /><param name="allowfullscreen" value="true" /></object></p>
<div style="font-size: 11px; font-family: tahoma,arial; height: 26px; padding-top: 2px;">View more <a style="text-decoration:underline;" href="http://www.slideshare.net/">presentations</a> from <a style="text-decoration:underline;" href="http://www.slideshare.net/snowgiraffe">Blythe Dunham</a>.</div>
</div>
<p>Some <a href="http://snowgiraffe.com/downloads/presentations/RailsConf2009SMS.ppt">ppt slides</a> for you. Slide share soon to come.</p>
<p><img class="aligncenter size-medium wp-image-476" title="railsyodawg" src="http://www.snowgiraffe.com/tech/wp-content/uploads/2009/05/railsyodawg-300x192.jpg" alt="railsyodawg" width="300" height="192" /></p>
<h2><a href="http://github.com/blythedunham/smsonrails">SMS On Rails</a><a href="http://snowgiraffe.com/rdocs/sms_on_rails/"> rdoc</a></h2>
<pre>script/plugin install git://github.com/blythedunham/smsonrails</pre>
<p>At the end of the snowgiraffe SMS show, I demoed the <a href="http://github.com/blythedunham/smsonrails">sms on rails engine plugin</a>. I&#8217;ll build it into a gem soon, but by using the generator there shouldn&#8217;t be any collisions, and the plugin should be version safe as everything is namespaced and modularized. Anyhow, here&#8217;s the script:</p>
<pre>&gt; rails dog --database=mysql
&gt; mysqladmin -uroot create dog_development
&gt; cd dog
&gt; script/plugin install git://github.com/blythedunham/smsonrails
&gt; script/generate sms_on_rails setup --default-service-provider=clickatell
&gt; rake db:migrate
&gt; mate config/environment.rb</pre>
<p>Sign up for <a href="http://clickatell.com">clickatell</a> and update the environment.rb with your credentials. Alternatively, use the email gateway (specify no default service provider) and setup your mail settings.</p>
<p>The Generator does the following:</p>
<ol>
<li> copy images and stylesheets to your public directory</li>
<li> generates 3 database migrations (the 2nd and 3rd have a 2 and 3 appended)</li>
<li>installs clickatell gem and static_record_cache plugin (for email carriers caching)</li>
<li>insert configuration into environment.rb</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.snowgiraffe.com/tech/475/railsconf-2009-integrating-sms-with-your-rails-application/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Rails Devs for Data Integrity: How to gracefully handle database key violations</title>
		<link>http://www.snowgiraffe.com/tech/462/rails-devs-for-foreign-keys/</link>
		<comments>http://www.snowgiraffe.com/tech/462/rails-devs-for-foreign-keys/#comments</comments>
		<pubDate>Sat, 25 Apr 2009 02:18:06 +0000</pubDate>
		<dc:creator>blythe</dc:creator>
				<category><![CDATA[ActiveRecord]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Plugins]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[ar-extensions]]></category>
		<category><![CDATA[foreign keys]]></category>
		<category><![CDATA[Rails Devs for Data Integrity]]></category>
		<category><![CDATA[unique keys]]></category>

		<guid isPermaLink="false">http://www.snowgiraffe.com/tech/?p=462</guid>
		<description><![CDATA[Join the club: Rails Devs for Data Integrity
Some ways to handle unique and foreign key violations database exceptions gracefully in rails.]]></description>
			<content:encoded><![CDATA[<div id="attachment_468" class="wp-caption alignright" style="width: 310px"><img class="size-medium wp-image-468" title="treehouse-fall-04-gif" src="http://www.snowgiraffe.com/tech/wp-content/uploads/2009/04/treehouse-fall-04-gif-300x197.gif" alt="Join the club! Rails Devs for Data Integrity" width="300" height="197" /><p class="wp-caption-text">Join the club! Rails Devs for Data Integrity</p></div>
<p><span style="color: #ff6600;"><strong>I am a Rails Developer and I believe in data integrity. </strong></span>There I said it! And look, there are lots of people in the club. Jer on Rails had an<a href="http://jeronrails.blogspot.com/2008/01/you-should-use-foreign-key-constraints.html"> awesome post in support for foreign keys</a> a while back.</p>
<p>After my talk on supercharging ActiveRecord to behave in an enterprise environment at the<a href="http://www.snowgiraffe.com/tech/446/mysql-conf-09/"> MySQL conference</a>, a lot of folks were interested in how to get around the Rails <span class="inline_code">ActiveRecord</span> errors that appear when one starts deifying the Rails Way and uses foreign keys and unique indexes on the database. Well I thought about it and came up with not only a list but a yet another new plugin <a href="http://github.com/blythedunham/rails_devs_for_data_integrity" target="_blank">rails_devs_for_data_integrity</a> to help deal with some of the errors. So when someone tells you not to use foreign keys, don&#8217;t listen and<span style="color: #ff6600;"> join the Rails Devs for Data Integrity</span>! Here is how to have em, and still make pretty Rails apps.</p>
<p><span style="color: #ff6600;">Super list&#8230;.</span></p>
<p><span id="more-462"></span></p>
<h2>Unique Keys</h2>
<h3>Use validates_uniqueness_of</h3>
<p>validates_uniqueness_of introduces a query to check unique records before insert or update, but alone doesn&#8217;t guaranty uniqueness in a multi server/multi mongrel environment. By using it conjunction with a unique key on the database, you have proper rails error messages and your safety belt to retain data integrity. In most cases when dealing with a single instance (a single user&#8217;s user name for example), I can afford to eat the overhead of the rails validates_uniqueness_of query.</p>
<h3>Use on duplicate key update and ignore</h3>
<p><a href="http://github.com/zdennis/ar-extensions">ar-extensions 0.9.1</a> supports ON DUPLICATE KEY UPDATE and IGNORE for MySQL on import, save, and create (all inserts and updates). This is especially practical for import (bulk insert) where validating each record&#8217;s uniqueness would produce a lot of overhead.</p>
<h3>Catch and Handle the Duplicate Violation Exception</h3>
<p>I wrote a lot of custom code in models and controllers to catch MySQL duplicate key error (<span class="inline_code">ActiveRecord::StatementInvalid</span>) and handle them appropriately. Typically, I added a new error to ActiveRecord::Base.errors, which is then displayed nicely with <span class="inline_code">error_messages_for</span> in the view. Sometimes this was done often with a save_safe model method possibly aliased to save or a rescue on the controller action.</p>
<p>After MySQLConf I decided to write a little plugin <a href="http://github.com/blythedunham/rails_devs_for_data_integrity">rails_devs_for_data_integrity</a> to convert exceptions into ActiveRecord errors (like validations do) for tables with unique and foreign keys . Its still infantile (and without tests, gasp!) but if anyone likes to find bugs, hit me up on<a href="http://github.com/blythedunham/rails_devs_for_data_integrity/issues"> githubs new issue tracker</a>. If there is more than one unique key per table, you might want write some custom error handling methods.</p>
<pre>script/plugin install git://github.com/blythedunham/rails_devs_for_data_integrity.git</pre>
<pre class="ruby"> <span class="keyword">class </span><span class="class">User</span> <span class="punct">&lt;</span> <span class="constant">ActiveRecord</span><span class="punct">::</span><span class="constant">Base</span>
   <span class="ident">handle_unique_key_violation</span>  <span class="symbol">:user_name</span><span class="punct">,</span> <span class="symbol">:message</span> <span class="punct">=&gt;</span> <span class="punct">'</span><span class="string">is taken"
   handle_foreign_key_violation :primary_email_id, :message =&gt; </span><span class="punct">'</span><span class="ident">is</span> <span class="keyword">not</span> <span class="ident">available</span><span class="punct">'</span><span class="string">
 end<span class="normal">

</span></span></pre>
<p>Will write ActiveRecord errors instead of nasty MySQL errors:</p>
<pre> &gt;&gt; user.errors.on(:user_name)
 =&gt; "association does not exist."

 &gt;&gt; user.errors.on(:primary_email_id)
 =&gt; "is a duplicate."</pre>
<h3>Overwrite <em>rescue_action_in_public</em> in ApplicationController</h3>
<p>Its a good idea to either send the user to a pretty 404 static generic error page (fast) or write some custom code in rescue_action_in_public. One idea is to create <span class="inline_code">DisplayableException</span> and subclass any exceptions where the text can be displayed to the user. If this is thrown, show <span class="inline_code">exeception.to_s</span>, if not show a generic error.</p>
<pre class="ruby"><span class="keyword">def </span><span class="method">rescues_action_in_public</span><span class="punct">(</span><span class="ident">exception</span><span class="punct">)</span>
  <span class="attribute">@message</span> <span class="punct">=</span> <span class="keyword">if</span> <span class="ident">exception</span><span class="punct">.</span><span class="ident">is_a?</span><span class="punct">(</span><span class="constant">DisplayableException</span><span class="punct">)</span>
    <span class="ident">exception</span><span class="punct">.</span><span class="ident">to_s</span>
  <span class="keyword">else</span>
    <span class="punct">"</span><span class="string">Sorry but an error occurred. Please contact your mommy.</span><span class="punct">"</span>
  <span class="keyword">end</span>
  <span class="ident">render</span> <span class="symbol">:action</span> <span class="punct">=&gt;</span> <span class="punct">'</span><span class="string">error_page</span><span class="punct">'</span>
<span class="keyword">end</span></pre>
<h2>Foreign Keys</h2>
<p>I have been using the <a href="http://agilewebdevelopment.com/plugins/owner/89">Redhills foreign key migration plugin</a> for a long time and haven&#8217;t had too much trouble with foreign key violations.</p>
<h3>Trouble Deleting Records</h3>
<p>At one point <span class="inline_code">ON DELETE</span> was not specified to <span class="inline_code">SET NULL</span> or <span class="inline_code">CASCADE</span> on many dependent columns and there was trouble deleting rows. Reindexing the database with this option was the solution. Similarly,  one could use <span class="inline_code">ON UPDATE</span> on foreign key indexes.  However, due to the way ActiveRecord works and doesn&#8217;t really update id columns, I haven&#8217;t had any issues.</p>
<h3>Foreign Key Validation Errors</h3>
<p>This has happened so seldom that I never worried about it. That&#8217;s what the refresh button is for! Perhaps its because most users have their own data and aren&#8217;t really modifying and deleting simultaneously. However, sure this can happen and it throws an <span class="inline_code">ActiveRecord::StatementInvalid</span> exception as with unique key violations. I would recommend the same approach as for unique keys: catch and handle the exception. I added foreign key support to the <a href="http://github.com/blythedunham/rails_devs_for_data_integrity" target="_blank">rails_devs_for_data_integrity plugin</a> experiment. Yay!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.snowgiraffe.com/tech/462/rails-devs-for-foreign-keys/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
