<?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>Jason Seifer &#187; Ruby</title>
	<atom:link href="http://jasonseifer.com/category/ruby/feed" rel="self" type="application/rss+xml" />
	<link>http://jasonseifer.com</link>
	<description></description>
	<lastBuildDate>Fri, 27 Aug 2010 23:11:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Rails 3.0 rc2 Notes</title>
		<link>http://jasonseifer.com/2010/08/24/rails-3-rc2</link>
		<comments>http://jasonseifer.com/2010/08/24/rails-3-rc2#comments</comments>
		<pubDate>Tue, 24 Aug 2010 04:00:07 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rc]]></category>

		<guid isPermaLink="false">http://jasonseifer.com/?p=518</guid>
		<description><![CDATA[With the recent release of Rails 3.0 Release Candidate 2, DHH posted on the official Rails blog to check out the sweet GitHub compare view between the two RCs for detailed information. This list is by no means complete but I made some notes from the commit view, with links where possible, about the bigger [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p>
With the recent release of <a href="http://weblog.rubyonrails.org/2010/8/24/rails-3-0-release-candidate-2">Rails 3.0 Release Candidate 2</a>, DHH posted on the official Rails blog to check out the sweet <a href="http://github.com/rails/rails/compare/v3.0.0_RC...v3.0.0_RC2">GitHub compare view</a> between the two RCs for detailed information. This list is by no means complete but I made some notes from the commit view, with links where possible, about the bigger changes:
</p>
<ul>
<li>Add a header that tells Internet Explorer (all versions) to use the best available standards support. [Yehuda Katz]</li>
<li>Rename <code>_snowman</code> to <code>_e</code>. <strong>Update:</strong> This was later updated to <code>utf8</code> as Kieran and Santiago point out in the comments.</li>
<li>Mysql2 is now the default mysql adapter.</li>
<li><code>render :file</code> is deprecated in favor of <code>render :template</code> except for absolute paths.</li>
<li>Apps upgrading from version 2.3 get defaulted to utf-8.</li>
<li><a href="http://github.com/rails/rails/commit/06af2913466acb88d46fc18b60c13f5c071395b1">Update documentation on <code>autosave</code></a>.</li>
<li>Several performance <a href="http://github.com/rails/rails/commit/fb6edb1769229fff66bf23a7c2e9d52cf26359c8">improvements</a> <a href="http://github.com/rails/rails/commit/dac2b37b037587053b53cb6ed3c67a1fd4339778">mostly</a> <a href="http://github.com/rails/rails/commit/ff760dd6ceee4414e54afdb346c322dee6280edc">by</a> <a href="http://github.com/rails/rails/commit/c8509d5303db0fd0930d09357b059bb4a6b19f9f">tenderlove</a>.</li>
<li>Tons of deprecations.</li>
<li><a href="http://github.com/rails/rails/commit/82eff0ffe977674ccf49bf192dacabd04b195995">Require rdoc version 2.5.10</a></li>
<li><a href="http://github.com/rails/rails/commit/6edae4553ee0f95d3a9a9de278db12c3ce880ef9">Require rack-mount 0.6.12</a></li>
<p></u></p>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=Rails+3.0+rc2+Notes+http://bit.ly/bUXRBX" title="Post to Twitter"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-twitter-micro1.png" alt="Post to Twitter" /></a> <a class="tt" href="http://delicious.com/post?url=http://jasonseifer.com/2010/08/24/rails-3-rc2&amp;title=Rails+3.0+rc2+Notes" title="Post to Delicious"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-delicious.png" alt="Post to Delicious" /></a> <a class="tt" href="http://delicious.com/post?url=http://jasonseifer.com/2010/08/24/rails-3-rc2&amp;title=Rails+3.0+rc2+Notes" title="Post to Delicious">Delicious</a> <a class="tt" href="http://digg.com/submit?url=http://jasonseifer.com/2010/08/24/rails-3-rc2&amp;title=Rails+3.0+rc2+Notes" title="Post to Digg"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-digg.png" alt="Post to Digg" /></a> <a class="tt" href="http://digg.com/submit?url=http://jasonseifer.com/2010/08/24/rails-3-rc2&amp;title=Rails+3.0+rc2+Notes" title="Post to Digg">Digg This Post</a> <a class="tt" href="http://www.facebook.com/share.php?u=http://jasonseifer.com/2010/08/24/rails-3-rc2&amp;t=Rails+3.0+rc2+Notes" title="Post to Facebook"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-facebook.png" alt="Post to Facebook" /></a> <a class="tt" href="http://www.facebook.com/share.php?u=http://jasonseifer.com/2010/08/24/rails-3-rc2&amp;t=Rails+3.0+rc2+Notes" title="Post to Facebook">Facebook</a> <a class="tt" href="http://reddit.com/submit?url=http://jasonseifer.com/2010/08/24/rails-3-rc2&amp;title=Rails+3.0+rc2+Notes" title="Post to Reddit"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-reddit.png" alt="Post to Reddit" /></a> <a class="tt" href="http://reddit.com/submit?url=http://jasonseifer.com/2010/08/24/rails-3-rc2&amp;title=Rails+3.0+rc2+Notes" title="Post to Reddit">Reddit This Post</a></p>

<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://jasonseifer.com/2010/08/24/rails-3-rc2/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Rake Tutorial</title>
		<link>http://jasonseifer.com/2010/04/06/rake-tutorial</link>
		<comments>http://jasonseifer.com/2010/04/06/rake-tutorial#comments</comments>
		<pubDate>Tue, 06 Apr 2010 08:25:09 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[rake]]></category>

		<guid isPermaLink="false">http://jasonseifer.com/?p=388</guid>
		<description><![CDATA[If you&#8217;re developing with Rails you&#8217;ve probably encountered rake once or twice. This blog post aims to walk you through where rake came from and an introduction on how to use it effectively in your Rails apps. A Little Bit of History Rake is the project of Jim Weirich. It&#8217;s a build tool. For a [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p><img class="alignright" src="http://farm4.static.flickr.com/3531/3183114977_da7c827934_m.jpg" /></p>
<p>If you&#8217;re developing with Rails you&#8217;ve probably encountered rake once or twice. This blog post aims to walk you through where rake came from and an introduction on how to use it effectively in your Rails apps.</p>
<h3>A Little Bit of History</h3>
<p>
  Rake is the project of <a href="http://onestepback.org">Jim Weirich</a>. It&#8217;s a build tool. For a good laugh and an even more in depth history check out the &quot;<a href="http://rake.rubyforge.org/files/doc/rational_rdoc.html">rational.rdoc</a>&quot; from the Rake documentation.  Essentially, rake started as an idea for using Ruby inside of a Makefile. Though Jim doesn&#8217;t sound convinced from the tone in that document, it <em>is</em> a good idea.
</p>
<p>What&#8217;s the need for an automated build system at all? As usual, <a href="http://en.wikipedia.org/wiki/Build_tool">Wikipedia</a> has the answer:</p>
<blockquote><p>
  Historically, developers used build automation to call compilers and linkers from inside a build script versus attempting to make the compiler calls from the command line. It is simple to use the command line to pass a single source module to a compiler and then to a linker to create the final deployable object. However, when attempting to compile and link many source code modules, in a particular order, using the command line process is not a reasonable solution. [sic]<br />
  As the build process grew more complex, developers began adding pre and post actions around the calls to the compilers such as a check-out from version control to the copying of deployable objects to a test location. The term &#8220;build automation&#8221; now includes managing the pre and post compile and link activities as well as the compile and link activities.
  </p></blockquote>
<h3>It&#8217;s about Dependencies</h3>
<p>
  This may be a bit of a stretch to say but build tools are about dependencies. One file or set of files depends on another set to get compiled, linked, or other fun things before the next set can be processed. The same idea exists in rake with tasks and task dependencies. Let&#8217;s look at a simple rake task. Save the following as &#8220;Rakefile&#8221; in any directory:
</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">  directory <span style="color:#996600;">&quot;tmp&quot;</span>
&nbsp;
  file <span style="color:#996600;">&quot;hello.tmp&quot;</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;tmp&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    sh <span style="color:#996600;">&quot;echo 'Hello' &gt;&gt; 'tmp/hello.tmp'&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>What we&#8217;re saying here is that the file named &#8220;hello.tmp&#8221; depends on the directory &quot;tmp&quot;. When rake runs across this, it&#8217;s going to create the directory &quot;tmp&quot; first before running the &quot;hello.tmp&quot; task. When you run it, you&#8217;ll see something like the following:
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">  <span style="color: #7a0874; font-weight: bold;">&#91;</span>jason<span style="color: #000000; font-weight: bold;">@</span>brick:~<span style="color: #000000; font-weight: bold;">/</span>src<span style="color: #7a0874; font-weight: bold;">&#93;</span>$ rake hello.tmp
  <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>jason<span style="color: #000000; font-weight: bold;">/</span>src<span style="color: #7a0874; font-weight: bold;">&#41;</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">'Hello'</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #ff0000;">'tmp/hello.tmp'</span></pre></div></div>

<p>If you were to look at the &quot;hello.tmp&quot; file you would see the phrase &quot;Hello&quot;. What happens if you run it again? You&#8217;ll see the same output again. What&#8217;s going on? Rake is generating the file again. It&#8217;s doing this because it can&#8217;t actually find the file tmp/hello.tmp from that definition. Let&#8217;s redefine the task:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">  directory <span style="color:#996600;">&quot;tmp&quot;</span>
&nbsp;
  file <span style="color:#996600;">&quot;tmp/hello.tmp&quot;</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;tmp&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    sh <span style="color:#996600;">&quot;echo 'Hello' &gt; 'tmp/hello.tmp'&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Now if you were to run it twice you would see something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">  <span style="color: #7a0874; font-weight: bold;">&#91;</span>jason<span style="color: #000000; font-weight: bold;">@</span>brick:~<span style="color: #000000; font-weight: bold;">/</span>src<span style="color: #7a0874; font-weight: bold;">&#93;</span>$ rake <span style="color: #ff0000;">&quot;tmp/hello.tmp&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>jason<span style="color: #000000; font-weight: bold;">/</span>src<span style="color: #7a0874; font-weight: bold;">&#41;</span>
  <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #660033;">-p</span> tmp
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">'Hello'</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #ff0000;">'tmp/hello.tmp'</span>
  <span style="color: #7a0874; font-weight: bold;">&#91;</span>jason<span style="color: #000000; font-weight: bold;">@</span>brick:~<span style="color: #000000; font-weight: bold;">/</span>src<span style="color: #7a0874; font-weight: bold;">&#93;</span>$ rake <span style="color: #ff0000;">&quot;tmp/hello.tmp&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>jason<span style="color: #000000; font-weight: bold;">/</span>src<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>Rake now knows that the file task has been run.</p>
<h3>Running Other Tasks</h3>
<p>
  Rake tasks can take the form of having prerequisites and can <em>depend on</em> another task. Let&#8217;s say I wanted to get ready in the morning. My process would be something like this:</p>
<ol>
<li>Turn off alarm clock.</li>
<li>Groom myself.</li>
<li>Make coffee.</li>
<li>Walk dog.</li>
</ol>
<p>
  Let&#8217;s further assume that I have OCD and have to do all of these in order. In rake I might express my morning as follows:
</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">  task <span style="color:#ff3333; font-weight:bold;">:turn_off_alarm</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Turned off alarm. Would have liked 5 more minutes, though.&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  task <span style="color:#ff3333; font-weight:bold;">:groom_myself</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Brushed teeth.&quot;</span>
    <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Showered.&quot;</span>
    <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Shaved.&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  task <span style="color:#ff3333; font-weight:bold;">:make_coffee</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    cups = ENV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;COFFEE_CUPS&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">||</span> <span style="color:#006666;">2</span>
    <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Made #{cups} cups of coffee. Shakes are gone.&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  task <span style="color:#ff3333; font-weight:bold;">:walk_dog</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Dog walked.&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  task <span style="color:#ff3333; font-weight:bold;">:ready_for_the_day</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:turn_off_alarm</span>, <span style="color:#ff3333; font-weight:bold;">:groom_myself</span>, <span style="color:#ff3333; font-weight:bold;">:make_coffee</span>, <span style="color:#ff3333; font-weight:bold;">:walk_dog</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Ready for the day!&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>If I were to run this as is I would type <code>rake ready_for_the_day</code> and I&#8217;d see the following:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">  <span style="color: #7a0874; font-weight: bold;">&#91;</span>jason<span style="color: #000000; font-weight: bold;">@</span>brick:~<span style="color: #000000; font-weight: bold;">/</span>src<span style="color: #7a0874; font-weight: bold;">&#93;</span>$ rake ready_for_the_day
  <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>jason<span style="color: #000000; font-weight: bold;">/</span>src<span style="color: #7a0874; font-weight: bold;">&#41;</span>
  Turned off alarm. Would have liked <span style="color: #000000;">5</span> <span style="color: #c20cb9; font-weight: bold;">more</span> minutes, though.
  Brushed teeth.
  Showered.
  Shaved.
  Made <span style="color: #000000;">5</span> cups of coffee. Shakes are gone.
  Dog walked.
  Ready <span style="color: #000000; font-weight: bold;">for</span> the day<span style="color: #000000; font-weight: bold;">!</span></pre></div></div>

<p>By running the <code>ready_for_the_day</code> task it notices that the <code>turn_off_alarm, groom_myself, make_coffee, and walk_dog</code> tasks are all prerequisites of the <code>ready_for_the_day</code> task. Then it runs them all in the appropriate order. You&#8217;ll notice that we can pass something in to the <code>make_coffee</code> task. If we were having a really tough day we could pass in a value to the COFFEE_CUPS environment variable and be more prepared:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">  <span style="color: #7a0874; font-weight: bold;">&#91;</span>jason<span style="color: #000000; font-weight: bold;">@</span>brick:~<span style="color: #000000; font-weight: bold;">/</span>src<span style="color: #7a0874; font-weight: bold;">&#93;</span>$ rake <span style="color: #007800;">COFFEE_CUPS</span>=<span style="color: #000000;">5</span> make_coffee
  <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>jason<span style="color: #000000; font-weight: bold;">/</span>src<span style="color: #7a0874; font-weight: bold;">&#41;</span>
  Made <span style="color: #000000;">5</span> cups of coffee. Shakes are gone.</pre></div></div>

</p>
<h3>Namespaces</h3>
<p>
  Rake supports the concept of namespaces which essentially lets you group together similar tasks inside of one namespace. You&#8217;d then specify the namespace when you call a task inside it.  It keeps things tidy while still being quite effective.  In Rails, you might notice the <code><strong>db</strong>:migrate</code> task. In that example, <code><strong>db</strong></code> is the namespace and migrate is the task. Using the above example, we might put everything in to the <code>morning</code> namespace:
</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">  namespace <span style="color:#ff3333; font-weight:bold;">:morning</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    task <span style="color:#ff3333; font-weight:bold;">:turn_of_alarm</span>
    ....
  <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Now if you were to run <code>rake COFFEE_CUPS=3 morning:ready_for_the_day</code> you would have the same output as above, only it only took 3 cups of coffee today. Score!</p>
<h3>The Default Task</h3>
<p>
  Rake has the concept of a <em>default</em> task. This is essentially the task that will be run if you type rake without any arguments. If we wanted our default task to be turning off the alarm from the example above, we&#8217;d do this:
</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">  task <span style="color:#ff3333; font-weight:bold;">:default</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'morning:turn_off_alarm'</span></pre></div></div>

<p>Running <code>rake</code> now produces the following:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">  <span style="color: #7a0874; font-weight: bold;">&#91;</span>jason<span style="color: #000000; font-weight: bold;">@</span>brick:~<span style="color: #000000; font-weight: bold;">/</span>src<span style="color: #7a0874; font-weight: bold;">&#93;</span>$ rake
  <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>jason<span style="color: #000000; font-weight: bold;">/</span>src<span style="color: #7a0874; font-weight: bold;">&#41;</span>
  Turned off alarm. Would have liked <span style="color: #000000;">5</span> <span style="color: #c20cb9; font-weight: bold;">more</span> minutes, though.</pre></div></div>

<h3>Describing Your Tasks</h3>
<p>You can use the <code>desc</code> method to describe your tasks. This is done on the line right above the task definition. It&#8217;s also what gives you that nice output when you run <coee>rake -T</coee> to get a list of tasks.  Tasks are displayed in alphabetical order. We&#8217;ll define some descriptions in our Rakefile (abbreviated for brevity):</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">  ...
  <span style="color:#9900CC;">desc</span> <span style="color:#996600;">&quot;Make coffee&quot;</span>
  task <span style="color:#ff3333; font-weight:bold;">:make_coffee</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    cups = ENV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;COFFEE_CUPS&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">||</span> <span style="color:#006666;">2</span>
    <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Made #{cups} cups of coffee. Shakes are gone.&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
  ...</pre></div></div>

<p>Now when we run <coee>rake -T</coee> for our list of tasks we get the following output:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">  <span style="color: #7a0874; font-weight: bold;">&#91;</span>jason<span style="color: #000000; font-weight: bold;">@</span>brick:~<span style="color: #000000; font-weight: bold;">/</span>src<span style="color: #7a0874; font-weight: bold;">&#93;</span>$ rake <span style="color: #660033;">-T</span>
  <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>jason<span style="color: #000000; font-weight: bold;">/</span>src<span style="color: #7a0874; font-weight: bold;">&#41;</span>
  rake afternoon:make_coffee      <span style="color: #666666; font-style: italic;"># Make afternoon coffee</span>
  rake morning:groom_myself       <span style="color: #666666; font-style: italic;"># Take care of normal hygeine tasks.</span>
  rake morning:make_coffee        <span style="color: #666666; font-style: italic;"># Make coffee</span>
  rake morning:ready_for_the_day  <span style="color: #666666; font-style: italic;"># Get ready for the day</span>
  rake morning:turn_off_alarm     <span style="color: #666666; font-style: italic;"># Turn off alarm.</span>
  rake morning:walk_dog           <span style="color: #666666; font-style: italic;"># Walk the dog</span></pre></div></div>

<p>You can add in a string to get tasks matching that displayed. Running <code>rake -T af</code> would show just the afternoon task.</p>
<h3>Redefining Tasks</h3>
<p>Let&#8217;s say you want to add on to an existing task. Perhaps you have another item in your grooming routine like styling your hair.  You could write another task and slip it in as a dependency for <code>groom_myself</code> but you could also redefine <code>groom_myself</code> later on (shortened for brevity but you get the idea):</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">  namespace <span style="color:#ff3333; font-weight:bold;">:morning</span> <span style="color:#9966CC; font-weight:bold;">do</span>
	....
	<span style="color:#9900CC;">task</span> <span style="color:#ff3333; font-weight:bold;">:groom_myself</span> <span style="color:#9966CC; font-weight:bold;">do</span>
      <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Brushed teeth.&quot;</span>
      <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Showered.&quot;</span>
      <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Shaved.&quot;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
    ....
  <span style="color:#9966CC; font-weight:bold;">end</span>
  ...
  <span style="color:#9900CC;">namespace</span> <span style="color:#ff3333; font-weight:bold;">:morning</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    task <span style="color:#ff3333; font-weight:bold;">:groom_myself</span> <span style="color:#9966CC; font-weight:bold;">do</span>
      <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Styled hair.&quot;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">  <span style="color: #7a0874; font-weight: bold;">&#91;</span>jason<span style="color: #000000; font-weight: bold;">@</span>brick:~<span style="color: #000000; font-weight: bold;">/</span>src<span style="color: #7a0874; font-weight: bold;">&#93;</span>$ rake morning:groom_myself
  <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>jason<span style="color: #000000; font-weight: bold;">/</span>src<span style="color: #7a0874; font-weight: bold;">&#41;</span>
  Brushed teeth.
  Showered.
  Shaved.
  Styled hair.</pre></div></div>

<p><img class="alignright" src="http://farm1.static.flickr.com/133/337248947_f1eadc7cc0_m.jpg" /></p>
<h3>Invoking Tasks</h3>
<p>
  You may at some point want to invoke a task from inside another task.  Let&#8217;s say, for example, you wanted to make coffee in the afternoon, too. If you need an extra upper after lunch you could do that the following way:
</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">  namespace <span style="color:#ff3333; font-weight:bold;">:afternoon</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    task <span style="color:#ff3333; font-weight:bold;">:make_coffee</span> <span style="color:#9966CC; font-weight:bold;">do</span>
      <span style="color:#6666ff; font-weight:bold;">Rake::Task</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'morning:make_coffee'</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">invoke</span>
      <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Ready for the rest of the day!&quot;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Which outputs:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">  <span style="color: #7a0874; font-weight: bold;">&#91;</span>jason<span style="color: #000000; font-weight: bold;">@</span>brick:~<span style="color: #000000; font-weight: bold;">/</span>src<span style="color: #7a0874; font-weight: bold;">&#93;</span>$ rake afternoon:make_coffee <span style="color: #007800;">COFFEE_CUPS</span>=<span style="color: #000000;">1</span>
  <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>jason<span style="color: #000000; font-weight: bold;">/</span>src<span style="color: #7a0874; font-weight: bold;">&#41;</span>
  Made <span style="color: #000000;">1</span> cups of coffee. Shakes are gone.
  Ready <span style="color: #000000; font-weight: bold;">for</span> the rest of the day<span style="color: #000000; font-weight: bold;">!</span></pre></div></div>

<p>A real world example of this is the <code>rcov:all</code> task. I use this in <a href="http://geniuspool.com">Genius Pool</a> for aggregate rcov data. It&#8217;s shamelessly stolen from <a href="http://www.claytonlz.com/index.php/2009/04/how-to-setup-rspec-cucumber-webrat-rcov-and-autotest-on-leopard/">Clayton Lengel-Zigich</a>. Go check out that post for a good example of invoking other tasks from rake.</p>
<h3>Refactoring</h3>
<p>
  You&#8217;ll notice in the example above we&#8217;re delegating most of the work to already defined methods and tasks in the RSpec and Cucumber classes. As a general rule, try to keep your methods already defined other places and call them from rake with your specific options and use cases.  Let&#8217;s say I had a Rails application that e-mailed all accounts in the system that their account was expiring in a certain number of days. Here&#8217;s one way to write it:
</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">  namespace <span style="color:#ff3333; font-weight:bold;">:accounts</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    desc <span style="color:#996600;">&quot;Email expiring accounts to let them know&quot;</span>
    task <span style="color:#ff3333; font-weight:bold;">:email_expiring</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:environment</span> <span style="color:#9966CC; font-weight:bold;">do</span>
      date = ENV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'from'</span><span style="color:#006600; font-weight:bold;">&#93;</span> ? <span style="color:#CC00FF; font-weight:bold;">Date</span>.<span style="color:#9900CC;">parse</span><span style="color:#006600; font-weight:bold;">&#40;</span>ENV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'from'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span> : <span style="color:#CC00FF; font-weight:bold;">Date</span>.<span style="color:#9900CC;">today</span>
      accounts = Account.<span style="color:#9900CC;">find</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:all</span>, <span style="color:#ff3333; font-weight:bold;">:conditions</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;expiration_date = ?&quot;</span>, date<span style="color:#006600; font-weight:bold;">&#93;</span>
      accounts.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>account<span style="color:#006600; font-weight:bold;">|</span>
        Notifier.<span style="color:#9900CC;">deliver_account_expiration</span><span style="color:#006600; font-weight:bold;">&#40;</span>account<span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>A better way, that would let you test it more thoroughly would be to do the following:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">  namespace <span style="color:#ff3333; font-weight:bold;">:accounts</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    desc <span style="color:#996600;">&quot;Email expiring accounts to let them know&quot;</span>
    task <span style="color:#ff3333; font-weight:bold;">:email_expiring</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:environment</span> <span style="color:#9966CC; font-weight:bold;">do</span>
      date = ENV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'from'</span><span style="color:#006600; font-weight:bold;">&#93;</span> ? <span style="color:#CC00FF; font-weight:bold;">Date</span>.<span style="color:#9900CC;">parse</span><span style="color:#006600; font-weight:bold;">&#40;</span>ENV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'from'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span> : <span style="color:#CC00FF; font-weight:bold;">Date</span>.<span style="color:#9900CC;">today</span>
      Account.<span style="color:#9900CC;">notify_expiring</span><span style="color:#006600; font-weight:bold;">&#40;</span>date<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>This lets you unit test your <code>notify_expiring</code> method on the account class and make sure that it&#8217;s doing what it&#8217;s supposed to do. This is a small, made up example, but you get the idea. Here&#8217;s an example from <a href="http://github.com/defunkt/resque/blob/master/tasks/redis.rake">Resque</a>:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">  desc <span style="color:#996600;">'Restart redis'</span>
  task <span style="color:#ff3333; font-weight:bold;">:restart</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    RedisRunner.<span style="color:#9900CC;">stop</span>
    RedisRunner.<span style="color:#9900CC;">start</span>
  <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Notice the delegation to the RedisRunner class methods? This is a great rake task</p>
<h3>Rails</h3>
<p>
  You can get access to your models, and in fact, your whole environment by making tasks dependent on the <code>environment</code> task. This lets you do things like run <code>rake RAILS_ENV=staging db:migrate</code>. Rails will <strong>autmatically pick up tasks in lib/tasks</strong>.  Any files named with the <code>.rake</code> extension will get picked up when you do <code>rake -T</code>.
</p>
<h3>Scheduling Rake Tasks</h3>
<p>
  You can use <a href="http://en.wikipedia.org/wiki/Cron">cron</a> to schedule rake tasks.  Let&#8217;s say you wanted to run the account email expiration task every night at 12:15 on your production server, you might have something like this:
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">  <span style="color: #000000;">15</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>data<span style="color: #000000; font-weight: bold;">/</span>my_app<span style="color: #000000; font-weight: bold;">/</span>current <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>rake <span style="color: #007800;">RAILS_ENV</span>=production accounts:email_expiring</pre></div></div>

<h3>Misc</h3>
<p>
  <code>Rake.original_dir</code> gives you the directory that the original rake task was run from.
</p>
<p></p>
<h3>Derivatives</h3>
<ul>
<li><a href="http://github.com/wycats/thor/">Thor</a> is a more class based approach to solving some of the things rake does as far as actual tasks go. </li>
<li><a href="http://capify.org">Capistrano</a> is the de facto standard for deploying rails apps. Its syntax is inspired pretty heavily by Rake, but it is definitely <em>not</em> rake.</li>
</ul>
<h3>Further Reading</h3>
<ul>
<li><a href="http://blog.jayfields.com/2006/11/ruby-testing-rake-tasks.html">&quot;Testing Rake Tasks&quot;</a> by Jay Fields</li>
<li><a href="http://www.jbarnette.com/2009/08/27/on-rake.html">&quot;On Rake&quot; by John Barnette</a></li>
<li><a href="http://www.claytonlz.com/index.php/2009/04/how-to-setup-rspec-cucumber-webrat-rcov-and-autotest-on-leopard/">How To: Setup RSpec, Cucumber, Webrat, RCov and Autotest on Leopard | Clayton Lengel-Zigich</a></li>
<li><a href="http://railscasts.com/episodes/66-custom-rake-tasks">Custom Rake Tasks</a> Railscast</li>
</ul>
<h3>Useful Rake Examples</h3>
<ul>
<li><a href="http://gist.github.com/359401">Sample Rakefile</a> from this article.</li>
<li><a href="http://github.com/defunkt/resque/blob/master/tasks/redis.rake">redis.rake</a> from Resque.</li>
</ul>
<p>If you have any more useful rake examples, please let me know and I&#8217;ll add them here.</p>
<p></p>
<p><strong>Photo Credits:</strong><br />
<strong><a href="http://www.flickr.com/photos/34094515@N00/3183114977/">Shaker rake</a></strong> by <a href="http://www.flickr.com/photos/34094515@N00/">dicktay2000</a> on Flickr.<br />
<strong><a href="http://www.flickr.com/photos/altemark/337248947/">Toy sampling megaphone</a></strong> by <a href="http://www.flickr.com/photos/altemark/">altemark</a> on Flickr.</p>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=Rake+Tutorial+http://bit.ly/b4Ed5O" title="Post to Twitter"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-twitter-micro1.png" alt="Post to Twitter" /></a> <a class="tt" href="http://delicious.com/post?url=http://jasonseifer.com/2010/04/06/rake-tutorial&amp;title=Rake+Tutorial" title="Post to Delicious"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-delicious.png" alt="Post to Delicious" /></a> <a class="tt" href="http://delicious.com/post?url=http://jasonseifer.com/2010/04/06/rake-tutorial&amp;title=Rake+Tutorial" title="Post to Delicious">Delicious</a> <a class="tt" href="http://digg.com/submit?url=http://jasonseifer.com/2010/04/06/rake-tutorial&amp;title=Rake+Tutorial" title="Post to Digg"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-digg.png" alt="Post to Digg" /></a> <a class="tt" href="http://digg.com/submit?url=http://jasonseifer.com/2010/04/06/rake-tutorial&amp;title=Rake+Tutorial" title="Post to Digg">Digg This Post</a> <a class="tt" href="http://www.facebook.com/share.php?u=http://jasonseifer.com/2010/04/06/rake-tutorial&amp;t=Rake+Tutorial" title="Post to Facebook"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-facebook.png" alt="Post to Facebook" /></a> <a class="tt" href="http://www.facebook.com/share.php?u=http://jasonseifer.com/2010/04/06/rake-tutorial&amp;t=Rake+Tutorial" title="Post to Facebook">Facebook</a> <a class="tt" href="http://reddit.com/submit?url=http://jasonseifer.com/2010/04/06/rake-tutorial&amp;title=Rake+Tutorial" title="Post to Reddit"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-reddit.png" alt="Post to Reddit" /></a> <a class="tt" href="http://reddit.com/submit?url=http://jasonseifer.com/2010/04/06/rake-tutorial&amp;title=Rake+Tutorial" title="Post to Reddit">Reddit This Post</a></p>

<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://jasonseifer.com/2010/04/06/rake-tutorial/feed</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>Rails Reminder: DATE_FORMATS</title>
		<link>http://jasonseifer.com/2010/03/10/rails-date-formats</link>
		<comments>http://jasonseifer.com/2010/03/10/rails-date-formats#comments</comments>
		<pubDate>Wed, 10 Mar 2010 14:49:39 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://jasonseifer.com/?p=340</guid>
		<description><![CDATA[A friend of mine recently asked me about adding time formats to Rails apps. It&#8217;s not completely intuitive on how to add new &#34;default&#34; symbols for date and time formats or to get a list of the built in ones. The API has the built-in lists of constants under DATE_FORMATS but it&#8217;s a bit difficult [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p>A friend of mine recently asked me about adding time formats to Rails apps.  It&#8217;s not completely intuitive on how to add new &quot;default&quot; symbols for date and time formats or to get a list of the built in ones.  The <a href="http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/Time/Conversions.html">API</a> has the built-in lists of constants under DATE_FORMATS but it&#8217;s a bit difficult to read on that page. Here&#8217;s a link to the current stable version of the Rails time formats: <a href="http://github.com/rails/rails/blob/2-3-stable/activesupport/lib/active_support/core_ext/time/conversions.rb">rails/activesupport/lib/active_support/core_ext/time/conversions.rb</a>.  In order to add new ones you use the ruby <a href="http://cheat.errtheblog.com/s/strftime/">strftime</a> function. </p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#6666ff; font-weight:bold;">ActiveSupport::CoreExtensions::<span style="color:#CC00FF; font-weight:bold;">Date</span>::Conversions::DATE_FORMATS</span>.<span style="color:#9900CC;">merge</span>!<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#123;</span>
  <span style="color:#ff3333; font-weight:bold;">:quick</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;%m %d, %Y at %I:%M %p&quot;</span>,
  <span style="color:#ff3333; font-weight:bold;">:end_date</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;%B %d, %Y&quot;</span>
<span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
<span style="color:#6666ff; font-weight:bold;">ActiveSupport::CoreExtensions::<span style="color:#CC00FF; font-weight:bold;">Time</span>::Conversions::DATE_FORMATS</span>.<span style="color:#9900CC;">merge</span>!<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#123;</span>
  <span style="color:#ff3333; font-weight:bold;">:job_list</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;%B %d, %Y&quot;</span>
<span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>This lets you do something like <code><%= model.created_at.to_s(:quick) %></code> in your code.</p>
<p>And here&#8217;s the <code>strftime</code> options from the cheat page as a refresher:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">  <span style="color:#006600; font-weight:bold;">%</span>a <span style="color:#006600; font-weight:bold;">-</span> The abbreviated weekday name <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">``</span>Sun<span style="color:#996600;">''</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#006600; font-weight:bold;">%</span>A <span style="color:#006600; font-weight:bold;">-</span> The  full  weekday  name <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">``</span>Sunday<span style="color:#996600;">''</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#006600; font-weight:bold;">%</span>b <span style="color:#006600; font-weight:bold;">-</span> The abbreviated month name <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">``</span>Jan<span style="color:#996600;">''</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#006600; font-weight:bold;">%</span>B <span style="color:#006600; font-weight:bold;">-</span> The  full  month  name <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">``</span>January<span style="color:#996600;">''</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#006600; font-weight:bold;">%</span>c <span style="color:#006600; font-weight:bold;">-</span> The preferred local date <span style="color:#9966CC; font-weight:bold;">and</span> time representation
  <span style="color:#006600; font-weight:bold;">%</span>d <span style="color:#006600; font-weight:bold;">-</span> Day of the month <span style="color:#006600; font-weight:bold;">&#40;</span>01..31<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#006600; font-weight:bold;">%</span>e <span style="color:#006600; font-weight:bold;">-</span> Day of the month without leading zeroes <span style="color:#006600; font-weight:bold;">&#40;</span>1..31<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#006600; font-weight:bold;">%</span>H <span style="color:#006600; font-weight:bold;">-</span> Hour of the day, <span style="color:#006666;">24</span><span style="color:#006600; font-weight:bold;">-</span>hour clock <span style="color:#006600; font-weight:bold;">&#40;</span>00..23<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#006600; font-weight:bold;">%</span>I <span style="color:#006600; font-weight:bold;">-</span> Hour of the day, <span style="color:#006666;">12</span><span style="color:#006600; font-weight:bold;">-</span>hour clock <span style="color:#006600; font-weight:bold;">&#40;</span>01..12<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#006600; font-weight:bold;">%</span>j <span style="color:#006600; font-weight:bold;">-</span> Day of the year <span style="color:#006600; font-weight:bold;">&#40;</span>001..366<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#006600; font-weight:bold;">%</span>k <span style="color:#006600; font-weight:bold;">-</span> Hour of the day, <span style="color:#006666;">24</span><span style="color:#006600; font-weight:bold;">-</span>hour clock w<span style="color:#006600; font-weight:bold;">/</span>o leading zeroes <span style="color:#006600; font-weight:bold;">&#40;</span> 0..23<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#006600; font-weight:bold;">%</span>l <span style="color:#006600; font-weight:bold;">-</span> Hour of the day, <span style="color:#006666;">12</span><span style="color:#006600; font-weight:bold;">-</span>hour clock w<span style="color:#006600; font-weight:bold;">/</span>o leading zeroes <span style="color:#006600; font-weight:bold;">&#40;</span> 1..12<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#006600; font-weight:bold;">%</span>m <span style="color:#006600; font-weight:bold;">-</span> Month of the year <span style="color:#006600; font-weight:bold;">&#40;</span>01..12<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#006600; font-weight:bold;">%</span>M <span style="color:#006600; font-weight:bold;">-</span> Minute of the hour <span style="color:#006600; font-weight:bold;">&#40;</span>00..59<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#006600; font-weight:bold;">%</span><span style="color:#CC0066; font-weight:bold;">p</span> <span style="color:#006600; font-weight:bold;">-</span> Meridian indicator <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">``</span>AM<span style="color:#996600;">''</span>  <span style="color:#9966CC; font-weight:bold;">or</span>  <span style="color:#996600;">``</span>PM<span style="color:#996600;">''</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#006600; font-weight:bold;">%</span><span style="color:#CC0066; font-weight:bold;">P</span> <span style="color:#006600; font-weight:bold;">-</span> Meridian indicator <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">``</span>am<span style="color:#996600;">''</span>  <span style="color:#9966CC; font-weight:bold;">or</span>  <span style="color:#996600;">``</span>pm<span style="color:#996600;">''</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#006600; font-weight:bold;">%</span>S <span style="color:#006600; font-weight:bold;">-</span> Second of the minute <span style="color:#006600; font-weight:bold;">&#40;</span>00..60<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#006600; font-weight:bold;">%</span>U <span style="color:#006600; font-weight:bold;">-</span> Week  number  of the current year,
          starting with the first Sunday as the first
          day of the first week <span style="color:#006600; font-weight:bold;">&#40;</span>00..53<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#006600; font-weight:bold;">%</span>W <span style="color:#006600; font-weight:bold;">-</span> Week  number  of the current year,
          starting with the first Monday as the first
          day of the first week <span style="color:#006600; font-weight:bold;">&#40;</span>00..53<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#006600; font-weight:bold;">%</span>w <span style="color:#006600; font-weight:bold;">-</span> Day of the week <span style="color:#006600; font-weight:bold;">&#40;</span>Sunday is <span style="color:#006666;">0</span>, 0..6<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#006600; font-weight:bold;">%</span>x <span style="color:#006600; font-weight:bold;">-</span> Preferred representation <span style="color:#9966CC; font-weight:bold;">for</span> the date alone, no time
  <span style="color:#006600; font-weight:bold;">%</span>X <span style="color:#006600; font-weight:bold;">-</span> Preferred representation <span style="color:#9966CC; font-weight:bold;">for</span> the time alone, no date
  <span style="color:#006600; font-weight:bold;">%</span>y <span style="color:#006600; font-weight:bold;">-</span> Year without a century <span style="color:#006600; font-weight:bold;">&#40;</span>00..99<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#006600; font-weight:bold;">%</span>Y <span style="color:#006600; font-weight:bold;">-</span> Year with century
  <span style="color:#006600; font-weight:bold;">%</span>Z <span style="color:#006600; font-weight:bold;">-</span> <span style="color:#CC00FF; font-weight:bold;">Time</span> zone name
  <span style="color:#006600; font-weight:bold;">%</span>z <span style="color:#006600; font-weight:bold;">-</span> <span style="color:#CC00FF; font-weight:bold;">Time</span> zone expressed as a UTC offset <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">``</span><span style="color:#006600; font-weight:bold;">-</span>04:00<span style="color:#996600;">''</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#006600; font-weight:bold;">%%</span> <span style="color:#006600; font-weight:bold;">-</span> Literal <span style="color:#996600;">``</span><span style="color:#006600; font-weight:bold;">%</span><span style="color:#996600;">''</span> character
&nbsp;
   t = <span style="color:#CC00FF; font-weight:bold;">Time</span>.<span style="color:#9900CC;">now</span>
   t.<span style="color:#9900CC;">strftime</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;Printed on %m/%d/%Y&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>   <span style="color:#008000; font-style:italic;">#=&gt; &quot;Printed on 04/09/2003&quot;</span>
   t.<span style="color:#9900CC;">strftime</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;at %I:%M%p&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>            <span style="color:#008000; font-style:italic;">#=&gt; &quot;at 08:56AM&quot;</span>
   t.<span style="color:#9900CC;">strftime</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;%e %B, %Y&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>	       <span style="color:#008000; font-style:italic;">#=&gt; &quot;9 April, 2003&quot;</span>
   t.<span style="color:#9900CC;">strftime</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;%Y-%m-%dT%H:%M:%S&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>     <span style="color:#008000; font-style:italic;">#=&gt; &quot;2003-04-09T08:56:07&quot; (EN 28601)</span></pre></div></div>

<p>The preferred method for doing this is to add these in an initializer in your app. Something along the lines of <code>config/initializers/my_time_formats.rb</code>.</p>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=Rails+Reminder%3A+DATE_FORMATS+http://bit.ly/8X3Vrn" title="Post to Twitter"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-twitter-micro1.png" alt="Post to Twitter" /></a> <a class="tt" href="http://delicious.com/post?url=http://jasonseifer.com/2010/03/10/rails-date-formats&amp;title=Rails+Reminder%3A+DATE_FORMATS" title="Post to Delicious"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-delicious.png" alt="Post to Delicious" /></a> <a class="tt" href="http://delicious.com/post?url=http://jasonseifer.com/2010/03/10/rails-date-formats&amp;title=Rails+Reminder%3A+DATE_FORMATS" title="Post to Delicious">Delicious</a> <a class="tt" href="http://digg.com/submit?url=http://jasonseifer.com/2010/03/10/rails-date-formats&amp;title=Rails+Reminder%3A+DATE_FORMATS" title="Post to Digg"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-digg.png" alt="Post to Digg" /></a> <a class="tt" href="http://digg.com/submit?url=http://jasonseifer.com/2010/03/10/rails-date-formats&amp;title=Rails+Reminder%3A+DATE_FORMATS" title="Post to Digg">Digg This Post</a> <a class="tt" href="http://www.facebook.com/share.php?u=http://jasonseifer.com/2010/03/10/rails-date-formats&amp;t=Rails+Reminder%3A+DATE_FORMATS" title="Post to Facebook"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-facebook.png" alt="Post to Facebook" /></a> <a class="tt" href="http://www.facebook.com/share.php?u=http://jasonseifer.com/2010/03/10/rails-date-formats&amp;t=Rails+Reminder%3A+DATE_FORMATS" title="Post to Facebook">Facebook</a> <a class="tt" href="http://reddit.com/submit?url=http://jasonseifer.com/2010/03/10/rails-date-formats&amp;title=Rails+Reminder%3A+DATE_FORMATS" title="Post to Reddit"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-reddit.png" alt="Post to Reddit" /></a> <a class="tt" href="http://reddit.com/submit?url=http://jasonseifer.com/2010/03/10/rails-date-formats&amp;title=Rails+Reminder%3A+DATE_FORMATS" title="Post to Reddit">Reddit This Post</a></p>

<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://jasonseifer.com/2010/03/10/rails-date-formats/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using the Rails logger outside of models and controllers</title>
		<link>http://jasonseifer.com/2009/08/10/using-the-rails-logger-outside-of-models-and-controllers</link>
		<comments>http://jasonseifer.com/2009/08/10/using-the-rails-logger-outside-of-models-and-controllers#comments</comments>
		<pubDate>Mon, 10 Aug 2009 16:39:43 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://jasonseifer.com/?p=210</guid>
		<description><![CDATA[You can use the Rails logger outside of Rails models in at least version 2.3.X and up of Rails. You might be used to doing the following in your models or controllers: logger.info &#34;Some debugging info I want to see in my development log.&#34; If you make a regular model that doesn&#8217;t inherit from ActiveRecord, [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p>
  You can use the Rails logger outside of Rails models in at least version 2.3.X and up of Rails.  You might be used to doing the following in your models or controllers:
</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">logger.<span style="color:#9900CC;">info</span> <span style="color:#996600;">&quot;Some debugging info I want to see in my development log.&quot;</span></pre></div></div>

<p>If you make a regular model that doesn&#8217;t inherit from ActiveRecord, though, you may see the following error:</p>
<pre>undefined local variable or method `logger' for #&lt;Class:0x42fd77c&gt;</pre>
</p>
<p>The solution is to call <strong>Rails</strong>.logger.info (or debug, or warn) as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">Rails.<span style="color:#9900CC;">logger</span>.<span style="color:#9900CC;">info</span> <span style="color:#996600;">&quot;Some debugging info I want to see in my development log.&quot;</span></pre></div></div>

<p>I hope that helps someone.</p>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=Using+the+Rails+logger+outside+of+models+and+controllers+http://bit.ly/dNmok" title="Post to Twitter"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-twitter-micro1.png" alt="Post to Twitter" /></a> <a class="tt" href="http://delicious.com/post?url=http://jasonseifer.com/2009/08/10/using-the-rails-logger-outside-of-models-and-controllers&amp;title=Using+the+Rails+logger+outside+of+models+and+controllers" title="Post to Delicious"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-delicious.png" alt="Post to Delicious" /></a> <a class="tt" href="http://delicious.com/post?url=http://jasonseifer.com/2009/08/10/using-the-rails-logger-outside-of-models-and-controllers&amp;title=Using+the+Rails+logger+outside+of+models+and+controllers" title="Post to Delicious">Delicious</a> <a class="tt" href="http://digg.com/submit?url=http://jasonseifer.com/2009/08/10/using-the-rails-logger-outside-of-models-and-controllers&amp;title=Using+the+Rails+logger+outside+of+models+and+controllers" title="Post to Digg"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-digg.png" alt="Post to Digg" /></a> <a class="tt" href="http://digg.com/submit?url=http://jasonseifer.com/2009/08/10/using-the-rails-logger-outside-of-models-and-controllers&amp;title=Using+the+Rails+logger+outside+of+models+and+controllers" title="Post to Digg">Digg This Post</a> <a class="tt" href="http://www.facebook.com/share.php?u=http://jasonseifer.com/2009/08/10/using-the-rails-logger-outside-of-models-and-controllers&amp;t=Using+the+Rails+logger+outside+of+models+and+controllers" title="Post to Facebook"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-facebook.png" alt="Post to Facebook" /></a> <a class="tt" href="http://www.facebook.com/share.php?u=http://jasonseifer.com/2009/08/10/using-the-rails-logger-outside-of-models-and-controllers&amp;t=Using+the+Rails+logger+outside+of+models+and+controllers" title="Post to Facebook">Facebook</a> <a class="tt" href="http://reddit.com/submit?url=http://jasonseifer.com/2009/08/10/using-the-rails-logger-outside-of-models-and-controllers&amp;title=Using+the+Rails+logger+outside+of+models+and+controllers" title="Post to Reddit"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-reddit.png" alt="Post to Reddit" /></a> <a class="tt" href="http://reddit.com/submit?url=http://jasonseifer.com/2009/08/10/using-the-rails-logger-outside-of-models-and-controllers&amp;title=Using+the+Rails+logger+outside+of+models+and+controllers" title="Post to Reddit">Reddit This Post</a></p>

<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://jasonseifer.com/2009/08/10/using-the-rails-logger-outside-of-models-and-controllers/feed</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Getting RSpec and TextMate to play nice</title>
		<link>http://jasonseifer.com/2009/08/05/getting-rspec-and-textmate-to-play-nice</link>
		<comments>http://jasonseifer.com/2009/08/05/getting-rspec-and-textmate-to-play-nice#comments</comments>
		<pubDate>Thu, 06 Aug 2009 04:17:08 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://jasonseifer.com/?p=206</guid>
		<description><![CDATA[Elijah Miller has a great blog post on getting TextMate and RSpec to play nicely together. This is pretty useful for just running specific spec files. Also, did you know you can get TextMate to automatically recognize spec files by naming them with the .spec extension and RSpec will recognize it? Link Delicious Digg This [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p><span class="outgoing_link_image" style="float:right"><a href="http://jqr.github.com/2009/02/06/textmate-rspec-and-dot-spec-party.html"><img src="http://jasonseifer.com/assets/2009/08/beer_labelsTextMate-Rspec-and-Dot-Spec-Party-__-Elijah-Miller-Build-20090805031252.jpg" alt="TextMate, Rspec and Dot Spec Party __ Elijah Miller - (Build 20090805031252).jpg" border="0" width="355" height="308" align="right" /><br />
</a></span></p>
<p>Elijah Miller has a great blog post on getting TextMate and RSpec to play nicely together.  This is pretty useful for just running specific spec files.  Also, did you know you can get TextMate to automatically recognize spec files by naming them with the .spec extension and RSpec will recognize it?<br />
<br />
<span class="outgoing_link"><a href="http://jqr.github.com/2009/02/06/textmate-rspec-and-dot-spec-party.html">Link</a></span></p>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=Getting+RSpec+and+TextMate+to+play+nice+http://bit.ly/30duUc" title="Post to Twitter"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-twitter-micro1.png" alt="Post to Twitter" /></a> <a class="tt" href="http://delicious.com/post?url=http://jasonseifer.com/2009/08/05/getting-rspec-and-textmate-to-play-nice&amp;title=Getting+RSpec+and+TextMate+to+play+nice" title="Post to Delicious"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-delicious.png" alt="Post to Delicious" /></a> <a class="tt" href="http://delicious.com/post?url=http://jasonseifer.com/2009/08/05/getting-rspec-and-textmate-to-play-nice&amp;title=Getting+RSpec+and+TextMate+to+play+nice" title="Post to Delicious">Delicious</a> <a class="tt" href="http://digg.com/submit?url=http://jasonseifer.com/2009/08/05/getting-rspec-and-textmate-to-play-nice&amp;title=Getting+RSpec+and+TextMate+to+play+nice" title="Post to Digg"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-digg.png" alt="Post to Digg" /></a> <a class="tt" href="http://digg.com/submit?url=http://jasonseifer.com/2009/08/05/getting-rspec-and-textmate-to-play-nice&amp;title=Getting+RSpec+and+TextMate+to+play+nice" title="Post to Digg">Digg This Post</a> <a class="tt" href="http://www.facebook.com/share.php?u=http://jasonseifer.com/2009/08/05/getting-rspec-and-textmate-to-play-nice&amp;t=Getting+RSpec+and+TextMate+to+play+nice" title="Post to Facebook"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-facebook.png" alt="Post to Facebook" /></a> <a class="tt" href="http://www.facebook.com/share.php?u=http://jasonseifer.com/2009/08/05/getting-rspec-and-textmate-to-play-nice&amp;t=Getting+RSpec+and+TextMate+to+play+nice" title="Post to Facebook">Facebook</a> <a class="tt" href="http://reddit.com/submit?url=http://jasonseifer.com/2009/08/05/getting-rspec-and-textmate-to-play-nice&amp;title=Getting+RSpec+and+TextMate+to+play+nice" title="Post to Reddit"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-reddit.png" alt="Post to Reddit" /></a> <a class="tt" href="http://reddit.com/submit?url=http://jasonseifer.com/2009/08/05/getting-rspec-and-textmate-to-play-nice&amp;title=Getting+RSpec+and+TextMate+to+play+nice" title="Post to Reddit">Reddit This Post</a></p>

<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://jasonseifer.com/2009/08/05/getting-rspec-and-textmate-to-play-nice/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Microsoft deems Ruby on Rails a competitor</title>
		<link>http://jasonseifer.com/2009/08/05/microsoft-deems-ruby-on-rails-a-competitor</link>
		<comments>http://jasonseifer.com/2009/08/05/microsoft-deems-ruby-on-rails-a-competitor#comments</comments>
		<pubDate>Wed, 05 Aug 2009 21:47:17 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://jasonseifer.com/2009/08/05/microsoft-deems-ruby-on-rails-a-competitor</guid>
		<description><![CDATA[Numerous commercial software vendors offer competing software applications for connectivity (both Internet and intranet), security, hosting, and e-business servers. System Center competes with server management and server virtualization platform providers, such as BMC, CA, Inc., Hewlett-Packard, IBM, and VMWare in the management of information technology infrastructures. Forefront security products compete with McAfee, Symantec, and Trend [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<div class="posterous_bookmarklet_entry">
<blockquote class="posterous_long_quote">
<p align="justify" style="margin-top: 0px; margin-bottom: 0px; text-indent: 2%;">Numerous commercial  software vendors offer competing software applications for connectivity (both Internet and intranet), security, hosting, and e-business servers. System Center competes with server management and server virtualization platform providers, such as BMC,  CA, Inc., Hewlett-Packard, IBM, and VMWare in the management of information technology infrastructures. Forefront security products compete with McAfee, Symantec, and Trend Micro in protecting both client and server applications. Our products for  software developers compete against offerings from Adobe, Borland, IBM, Oracle, Sun Microsystems, other companies, and open-source projects. Open source projects include Eclipse (sponsored by CA, IBM, Oracle, and SAP), PHP, and <strong>Ruby on Rails</strong>, among  others. We believe that our server products provide customers with advantages in innovation, performance, total costs of ownership, and productivity by delivering superior applications, development tools, and compatibility with a broad base of  hardware and software applications, security, and manageability. </p>
<p align="justify" style="margin-top: 12px; margin-bottom: 0px;">
</blockquote>
<div class="posterous_quote_citation">via <a href="http://www.sec.gov/Archives/edgar/data/789019/000119312509158735/d10k.htm">sec.gov</a></div>
<p>Emphasis mine.</p>
</div>
<p style="font-size: 10px;">  <a href="http://posterous.com">Posted via web</a>   from <a href="http://jasonseifer.posterous.com/microsoft-deems-ruby-on-rails-a-competitor">Jason&#8217;s posterous</a>  </p>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=Microsoft+deems+Ruby+on+Rails+a+competitor+http://bit.ly/PtRvj" title="Post to Twitter"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-twitter-micro1.png" alt="Post to Twitter" /></a> <a class="tt" href="http://delicious.com/post?url=http://jasonseifer.com/2009/08/05/microsoft-deems-ruby-on-rails-a-competitor&amp;title=Microsoft+deems+Ruby+on+Rails+a+competitor" title="Post to Delicious"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-delicious.png" alt="Post to Delicious" /></a> <a class="tt" href="http://delicious.com/post?url=http://jasonseifer.com/2009/08/05/microsoft-deems-ruby-on-rails-a-competitor&amp;title=Microsoft+deems+Ruby+on+Rails+a+competitor" title="Post to Delicious">Delicious</a> <a class="tt" href="http://digg.com/submit?url=http://jasonseifer.com/2009/08/05/microsoft-deems-ruby-on-rails-a-competitor&amp;title=Microsoft+deems+Ruby+on+Rails+a+competitor" title="Post to Digg"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-digg.png" alt="Post to Digg" /></a> <a class="tt" href="http://digg.com/submit?url=http://jasonseifer.com/2009/08/05/microsoft-deems-ruby-on-rails-a-competitor&amp;title=Microsoft+deems+Ruby+on+Rails+a+competitor" title="Post to Digg">Digg This Post</a> <a class="tt" href="http://www.facebook.com/share.php?u=http://jasonseifer.com/2009/08/05/microsoft-deems-ruby-on-rails-a-competitor&amp;t=Microsoft+deems+Ruby+on+Rails+a+competitor" title="Post to Facebook"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-facebook.png" alt="Post to Facebook" /></a> <a class="tt" href="http://www.facebook.com/share.php?u=http://jasonseifer.com/2009/08/05/microsoft-deems-ruby-on-rails-a-competitor&amp;t=Microsoft+deems+Ruby+on+Rails+a+competitor" title="Post to Facebook">Facebook</a> <a class="tt" href="http://reddit.com/submit?url=http://jasonseifer.com/2009/08/05/microsoft-deems-ruby-on-rails-a-competitor&amp;title=Microsoft+deems+Ruby+on+Rails+a+competitor" title="Post to Reddit"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-reddit.png" alt="Post to Reddit" /></a> <a class="tt" href="http://reddit.com/submit?url=http://jasonseifer.com/2009/08/05/microsoft-deems-ruby-on-rails-a-competitor&amp;title=Microsoft+deems+Ruby+on+Rails+a+competitor" title="Post to Reddit">Reddit This Post</a></p>

<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://jasonseifer.com/2009/08/05/microsoft-deems-ruby-on-rails-a-competitor/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Receiving Email with Rails</title>
		<link>http://jasonseifer.com/2009/04/24/receving-email-with-rails</link>
		<comments>http://jasonseifer.com/2009/04/24/receving-email-with-rails#comments</comments>
		<pubDate>Fri, 24 Apr 2009 04:58:28 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://jasonseifer.com/?p=186</guid>
		<description><![CDATA[This article originally appeared in the first issue of Rails Magazine. It is reproduced here not quite verbatim with a couple of corrections and additions. Photo from esparta on Flickr. Introduction Receiving email is a great way to add functionality to your application. This is one area, though, that is not very well documented with [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p><em>This article originally appeared in the first issue of <a href="http://railsmagazine.com">Rails Magazine</a>.  It is reproduced here not quite verbatim with a couple of corrections and additions.</em></p>
<div style="float:right; text-align:center; margin: 8px; padding: 3px; border: 1px solid #aaa"><img src="http://jasonseifer.com/assets/2009/04/423aefd3-8e36-43a1-b054-c16f860cf0fe.jpg" alt="423AEFD3-8E36-43A1-B054-C16F860CF0FE.jpg" border="0" width="240" height="160" align="right" /></p>
<p class="small">Photo from <a href="http://www.flickr.com/photos/esparta/1609874001/">esparta</a> on Flickr.</p>
</div>
<h2>Introduction</h2>
<p>Receiving email is a great way to add functionality to your application.  This is one area, though, that is not very well documented with Rails.  Sure, we have ActionMailer documentation, but how does something like this actually work in a production environment and what are the concerns?  I had to tackle this problem recently and no solution that was &#8220;in the wild&#8221; would work with the requirements I had for this application.  In this article, we will take a look at a couple of options and go in to detail with one method that has not recieved much coverage.</p>
<p>John Nunemaker, on the Rails Tips blog, posted a solution to this problem using GMail with IMAP to Receive Email in Rails<sup><a href="#railstips">(1)</a></sup>.  He uses a script to connect to an IMAP server every minute or so and polls for new e-mails.  The Rails environment is loaded and if there are new messages waiting, this is processed using an ActiveRecord model.  He uses the &#8216;Daemons&#8217; library to keep the script running and give it start/stop commands and keep a pidfile.</p>
<p>This is a perfectly valid and functional way to process e-mail.  The application I was working on, though, had to be able to handle and process e-mail in as little time as possible. People would likely be e-mailing things from their mobile phones and might want to check on them soon after an upload.  At that point, polling every X number of minutes wasn&#8217;t a viable solution, so I had to come up with something else.</p>
<p>It&#8217;s also worth noting that polling for email should take in to account your user base and size.  Let&#8217;s say that we have an app with 10,000 active users.  Let&#8217;s also say that during peak times, they <em>all</em> decide to email our application.  Finally, we&#8217;ll say that they are sending an average 5 emails apiece.  With these hypothetical numbers, this works out to about 833 emails per minute.  If your IMAP server is being polled every three minutes, that&#8217;s going to leave you about 3,332 e-mails to download and process each time.</p>
<h2>Configuring Your Email Server</h2>
<p>Email itself is a problem that has been largely solved.  There are a wealth of email servers available but  this article will take a look at Postfix.  Postfix is most easily installed using the package manager of your distribution and may already be installed if you have a VPS.  I prefer Ubuntu server side so this article will focus on that flavor. Just be aware that certain configuration file locations may vary depending on your distribution.  So let&#8217;s get started.</p>
<p>First we need to add or change some DNS records.  The instructions for how to do this will vary depending on how you have your DNS hosted. I personally use DNS Made Easy and recommend it to my clients as well, should they need DNS hosting. DNS Made Easy has very reasonable rates and quotas.  Regardless of your host you need to create the following records:</p>
<p><img src="http://jasonseifer.com/assets/2009/04/mxrecord.jpg" alt="mxrecord.t.jpg" border="0" width="636" height="332" align="right" /></p>
<ul>
<li>An &#8220;A&#8221; record that has your domain name only.</li>
<li>An &#8220;A&#8221; record that is just <code>"mail"</code>.</li>
<li>An &#8220;MX&#8221; record that is set to level 10 and points to &#8220;mail&#8221;</li>
<li>Optional: An SPF Record</li>
</ul>
<p>OK, I was lying.  The SPF record isn&#8217;t really optional. This is going to be a TXT Record and should read something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">	<span style="color: #007800;">v</span>=spf1 mx <span style="color: #660033;">-all</span></pre></div></div>

<p>There are several different variations you can use with SPF records but going through them would be beyond the scope of this article.  Do some research and pick the combination that&#8217;s right for your setup.</p>
<p>Now, the first thing that you&#8217;re going to need to do is figure out what address you want to receive mail as. This is going to be your catch-all address.  In this case we&#8217;re going to choose &quot;killerrobot&quot; because that just might keep spammers at bay<sup><a href="#spammers">(2)</a></sup>. I mean, who&#8217;s going to spam a killer robot? </p>
<p>Reading tutorials around the web or even looking in some books will tell you that you can tell postfix to forward mail simply by piping it in /etc/aliases.  You might be tempted to do something like pipe everything to a ruby script:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># /etc/aliases</span>
...
killerrobot: <span style="color: #ff0000;">&quot;|/usr/bin/ruby /var/www/apps/myapp/current/lib/mail_receiver.rb&quot;</span>
<span style="color: #000000; font-weight: bold;">*</span>: killerrobot</pre></div></div>

<p>This, unfortunately, won&#8217;t work.  If you do it this way, all of your scripts are going to run as root.  This is not what you want and can be a security concern.  The proper way to do this is with a postmap filter.  Open up /etc/postfix/master.cf.  The first line after all of the comments should look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># /etc/postfix/master.cf</span>
smtp      inet  n       -       -       -       -       smtpd</pre></div></div>

<p>Add a line right below that to tell postfix that you&#8217;re using a filter:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># /etc/postfix/master.cf</span>
smtp      inet  n       -       -       -       -       smtpd
 <span style="color: #660033;">-o</span> <span style="color: #007800;">content_filter</span>=myapp_filter:</pre></div></div>

<p>Then go all the way down to the bottom of the file and add your filter:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># /etc/postfix/master.cf </span>
smtp      inet  n       -       -       -       -       smtpd
 <span style="color: #660033;">-o</span> <span style="color: #007800;">content_filter</span>=myapp_filter:
...
myapp_filter unix -     n       n       -       -       pipe
 <span style="color: #007800;">flags</span>=Xhq <span style="color: #007800;">user</span>=deploy <span style="color: #007800;">argv</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>ruby <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/</span>apps<span style="color: #000000; font-weight: bold;">/</span>myapp<span style="color: #000000; font-weight: bold;">/</span>current<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>mail_receiver.rb</pre></div></div>

<p>The &#8220;X&#8221; parameter in &#8220;flags=Xhq&#8221; tells postfix that an external command performs final delivery.  This is going to change the message status from &#8220;relayed&#8221; to &#8220;delivered&#8221;.  The &#8220;h&#8221; flag sets the recipients and domains to lowercase, and the &#8220;q&#8221; flag quotes whitespace and other special characters.  Now, reload postfix by doing <code>sudo postfix reload</code>. At this point, you should have a very basic mail server configured to receive email and put it in to a <code>mail_receiver.rb</code> script.</p>
<h2>Handling The Email</h2>
<p>	We&#8217;re going to be putting all of our mail that comes in to a message queue and parsing it with the &#8216;mms2r&#8217; gem.  In this article I&#8217;m going to use beanstalkd<sup><a href="#beanstalkd">(3)</a></sup> but you could substitute your favorite message queue for this part of the architecture.  I&#8217;m going to assume that a message queue is already installed and running and that you have both the &#8216;tmail&#8217; and &#8216;mms2r&#8217; gems installed.</p>
<p>	We want our <code>mail_receiver</code> script to be super lean.  It&#8217;s only going to serve one function: put the incoming mail in to a queue.  We&#8217;ll process the queue later but for now we just want to get it in there and handle any attachments.  We want it to be super lean because if we&#8217;re receiving a lot of mail we don&#8217;t want this script to be memory intensive or take a long time to start up or run.  It will look something like this:
</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;">#!/usr/bin/env ruby</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rubygems'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'tmail'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'mms2r'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'beanstalk-client'</span>
&nbsp;
message = <span style="color:#ff6633; font-weight:bold;">$stdin</span>.<span style="color:#9900CC;">read</span>
mail = <span style="color:#6666ff; font-weight:bold;">TMail::Mail</span>.<span style="color:#9900CC;">parse</span><span style="color:#006600; font-weight:bold;">&#40;</span>message<span style="color:#006600; font-weight:bold;">&#41;</span>
mms = <span style="color:#6666ff; font-weight:bold;">MMS2R::Media</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>mail<span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">if</span> !mail.<span style="color:#9900CC;">to</span>.<span style="color:#0000FF; font-weight:bold;">nil</span>?
  BEANSTALK = <span style="color:#6666ff; font-weight:bold;">Beanstalk::Pool</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'127.0.0.1:11300'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  BEANSTALK.<span style="color:#9900CC;">yput</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#123;</span>:type <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'received_email'</span>, 
    <span style="color:#ff3333; font-weight:bold;">:to</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> mail.<span style="color:#9900CC;">to</span>.<span style="color:#9900CC;">flatten</span>.<span style="color:#9900CC;">first</span>.<span style="color:#CC0066; font-weight:bold;">gsub</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'@mydomain.com'</span>, <span style="color:#996600;">''</span><span style="color:#006600; font-weight:bold;">&#41;</span>, 
    <span style="color:#ff3333; font-weight:bold;">:tags</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> mail.<span style="color:#9900CC;">subject</span>, 
    <span style="color:#ff3333; font-weight:bold;">:attachment</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> mms.<span style="color:#9900CC;">default_media</span>.<span style="color:#9900CC;">path</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>What we&#8217;re doing here is taking the email message from standard input and parsing it by putting it in to a TMail object.  TMail is a great library that takes care of most of the formatting for us.  It lets us do things like refer to mail messages as objects and use <code>mail.to</code>, <code>mail.from</code>, etc.  If we have attachments, they&#8217;re going along as well.</p>
<p>MMS2R is an amazing piece of software.  It works for both emails and, as the name implies, MMS messages as well.  What makes it so amazing?  There are dozens of different formats that an attachment can come in from both email and MMS.  Different phone carriers each have their own way of doing MMS attachments, each of them slightly different.  MMS2R alleviates the problem of trying to parse all of these different formats and does it all for you.  In this way we can call <code>MMS2R::Media.new(mail)</code> and be done with it.</p>
<p>For the purposes of our example application, the user can tag the photos they upload by putting the different tags in the subject. We send that in as another option in the job hash for beanstalkd.  Each user is assigned a unique identifier in their account that lets them send email to the application, for example &#8220;aslkdf32@myapp.com&#8221;.  We grab the first recipient (mail.to) because that will come in as an array.  We take the domain out and send that in as the &#8220;to&#8221; field.  Finally, the temporary media location on disk that we parsed using MMS2R is thrown in to the queue as the :attachment option.  Our mail is in the queue.</p>
<h2>Processing the Queue</h2>
<p>Now that we have our email in the queue, we need to get it out. For this part, we&#8217;re actually going to load the Rails environment.  I have this in the <code>lib</code> directory.  The code would look something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;">#!/usr/bin/env ruby</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">dirname</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">__FILE__</span><span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#996600;">'..'</span>, <span style="color:#996600;">'config'</span>, <span style="color:#996600;">'environment'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rubygems'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'beanstalk-client'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'yaml'</span>
beanstalk_config = <span style="color:#CC00FF; font-weight:bold;">YAML</span>::<span style="color:#CC0066; font-weight:bold;">load</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#CC0066; font-weight:bold;">open</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;#{RAILS_ROOT}/config/beanstalk.yml&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
<span style="color:#0066ff; font-weight:bold;">@logger</span> = <span style="color:#CC00FF; font-weight:bold;">Logger</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;#{RAILS_ROOT}/log/queue.#{Rails.env}.log&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#0066ff; font-weight:bold;">@logger</span>.<span style="color:#9900CC;">level</span> = <span style="color:#6666ff; font-weight:bold;">Logger::INFO</span>
&nbsp;
BEANSTALK = <span style="color:#6666ff; font-weight:bold;">Beanstalk::Pool</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>beanstalk_config<span style="color:#006600; font-weight:bold;">&#91;</span>Rails.<span style="color:#9900CC;">env</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
<span style="color:#CC0066; font-weight:bold;">loop</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  job = BEANSTALK.<span style="color:#9900CC;">reserve</span>
  job_hash = job.<span style="color:#9900CC;">ybody</span>
  <span style="color:#9966CC; font-weight:bold;">case</span> job_hash<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:type</span><span style="color:#006600; font-weight:bold;">&#93;</span>
  <span style="color:#9966CC; font-weight:bold;">when</span> <span style="color:#996600;">'received_email'</span>
    <span style="color:#0066ff; font-weight:bold;">@logger</span>.<span style="color:#9900CC;">info</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;Got email: #{job_hash.inspect}&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">if</span> EmailProcessor.<span style="color:#9900CC;">process</span><span style="color:#006600; font-weight:bold;">&#40;</span>job_hash<span style="color:#006600; font-weight:bold;">&#41;</span>
      job.<span style="color:#9900CC;">delete</span>
    <span style="color:#9966CC; font-weight:bold;">else</span>
      <span style="color:#0066ff; font-weight:bold;">@logger</span>.<span style="color:#9900CC;">warn</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;Did not process email: #{job_hash.inspect}&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      job.<span style="color:#9900CC;">bury</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">else</span>
    <span style="color:#0066ff; font-weight:bold;">@logger</span>.<span style="color:#9900CC;">warn</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;Don't know how to process #{job_hash.inspect}&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>The first line loads the Rails environment so we have access to all of our ActiveRecord models.  We want to keep our code DRY and use only one method of processing an attachment, routing messages, or the like.  If we were using attachment_fu or paperclip, we would keep this code in the model.  You might even want to make a seprate class, such a presenter, for your logic.  In this case the EmailProcessor class finds the user based on the reception_email attribute and then executes the &#8220;do_stuff&#8221; method to process the message.  It would look something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'local_file'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'tmail'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'mms2r'</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">class</span> EmailProcessor
  attr_accessor <span style="color:#ff3333; font-weight:bold;">:user</span>, <span style="color:#ff3333; font-weight:bold;">:options</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">process</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">*</span>args<span style="color:#006600; font-weight:bold;">&#41;</span>
    email_processor = new<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">*</span>args<span style="color:#006600; font-weight:bold;">&#41;</span>
    email_processor.<span style="color:#9900CC;">do_stuff</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> find_user
    <span style="color:#0066ff; font-weight:bold;">@user</span> = User.<span style="color:#9900CC;">find</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:first</span>, <span style="color:#ff3333; font-weight:bold;">:conditions</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span>:reception_email <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0066ff; font-weight:bold;">@options</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:to</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#125;</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> do_stuff
		<span style="color:#008000; font-style:italic;"># Your actual logic would go here...</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> initialize<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">*</span>args<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#0066ff; font-weight:bold;">@options</span> = args.<span style="color:#9900CC;">extract_options</span>!
    find_user
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>This uses the LocalFile class from Ben Rubenstein<sup><a href="#localfile">(4)</a></sup></p>
<p>We&#8217;re not quite done yet.  We need to make the <code>mail_processor</code> run as a daemon instead of just running &#8220;ruby mail_processor.rb&#8221; when we want to launch it.  We&#8217;ll use the &#8216;daemons&#8217; library for that.  This will take care of setting up PID files and lets us do <code>ruby mail_processor_control.rb start</code> and <code>ruby mail_processor_control.rb stop</code>.  We&#8217;re also using the &#8220;daemons_extension&#8221; file from Rapleaf that actually gives feedback on stopping of the daemon.  The script itself is extremely simple and goes in the <code>lib</code> directory with your <code>mail_processor.rb</code> script: </p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rubygems'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'daemons'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">dirname</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">__FILE__</span><span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#996600;">'daemons_extension'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
ENV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'RAILS_ENV'</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">||</span>= <span style="color:#996600;">'development'</span>
&nbsp;
options = <span style="color:#006600; font-weight:bold;">&#123;</span>
  <span style="color:#ff3333; font-weight:bold;">:app_name</span>  <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'processor'</span>,
  <span style="color:#ff3333; font-weight:bold;">:dir_mode</span>  <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:script</span>,
  <span style="color:#ff3333; font-weight:bold;">:dir</span>       <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'../log'</span>,
  <span style="color:#ff3333; font-weight:bold;">:backtrace</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>,
  <span style="color:#ff3333; font-weight:bold;">:mode</span>      <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:load</span>,
  <span style="color:#ff3333; font-weight:bold;">:monitor</span>   <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>
<span style="color:#006600; font-weight:bold;">&#125;</span>
&nbsp;
Daemons.<span style="color:#9900CC;">run</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">dirname</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">__FILE__</span><span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#996600;">'processor.rb'</span><span style="color:#006600; font-weight:bold;">&#41;</span>, options<span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>Now just start it by doing &#8220;<code>ruby mail_processor_control.rb start" </code>and your daemon will be up and running. That&#8217;s it! You&#8217;re receiving e-mail to your Rails app.  It is very important that you load the rails environment in your worker and not the daemon controller.  The controller only manages the worker, therefore it won&#8217;t have access to the Rails environment and will error out.</p>
<h2>Considerations</h2>
<p>Depending on your configuration, you may want to use a different message queue than beanstalkd.  I&#8217;ve personally  found beanstalkd to be reliable but your architecture might call for something else.  For example, you may want to put your message queue on another server.  If you did this then you wouldn&#8217;t have access to the temporary storage that MMS2R defaults to for saving the attachments.  In that case you could use a queue and put the attachments directly in the queue, on s3, etc.</p>
<p>Some people have reported problems using the daemons library and having their daemon just halt and stop responding.  I&#8217;ve never encountered that and I&#8217;ve had this similar setup running for months. You will also want to put your <code>mail_processor_control</code> under some sort of process supervision, such as by monit or god.</p>
<p>You may be asking yourself why we didn&#8217;t use ActionMailer to handle the incoming emails since it does that?  The answer is that if you do it the way it&#8217;s described, for example, on the Rails wiki, it will spin up a new Rails process for <em>each</em> email that&#8217;s received.  Under any significant load, this will fail<sup><a href="#railscantscale">(5)</a></sup>.  Another drawback to that approach is that if there is a failure, you lose the email.  With this type of architecture, it remains in the queue and you can just process it later.</p>
<h2>Conclusion</h2>
<p>This is a good start to handling email in your application.  Being able to process email is a great way to enhance your app and give your users mobile access. With email-capable phones becoming ubiquitous, they no longer need to be tied to a computer to use your app. Remember, an app that can be used anywhere is an app that will be used anywhere.</p>
<h3>Citations</h3>
<ol>
<li id="railstips"><a href="http://railstips.org/2008/10/27/using-gmail-with-imap-to-receive-email-in-rails">http://railstips.org/2008/10/27/using-gmail-with-imap-to-receive-email-in-rails</a></li>
<li id="stopspammers">No it won&#8217;t.</li>
<li id="beanstalkd"><a href="http://xph.us/software/beanstalkd/">http://xph.us/software/beanstalkd/</a></li>
<li id="localfile"><a href="http://www.benr75.com/articles/2008/01/04/attachment_fu-now-with-local-file-fu">http://www.benr75.com/articles/2008/01/04/attachment_fu-now-with-local-file-fu</a></li>
<li id="railscantscale">Because rails can&#8217;t scale.  See <a href="http://canrailsscale.com">http://canrailsscale.com</a> for more information.</li>
</ol>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=Receiving+Email+with+Rails+http://bit.ly/nFC0N" title="Post to Twitter"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-twitter-micro1.png" alt="Post to Twitter" /></a> <a class="tt" href="http://delicious.com/post?url=http://jasonseifer.com/2009/04/24/receving-email-with-rails&amp;title=Receiving+Email+with+Rails" title="Post to Delicious"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-delicious.png" alt="Post to Delicious" /></a> <a class="tt" href="http://delicious.com/post?url=http://jasonseifer.com/2009/04/24/receving-email-with-rails&amp;title=Receiving+Email+with+Rails" title="Post to Delicious">Delicious</a> <a class="tt" href="http://digg.com/submit?url=http://jasonseifer.com/2009/04/24/receving-email-with-rails&amp;title=Receiving+Email+with+Rails" title="Post to Digg"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-digg.png" alt="Post to Digg" /></a> <a class="tt" href="http://digg.com/submit?url=http://jasonseifer.com/2009/04/24/receving-email-with-rails&amp;title=Receiving+Email+with+Rails" title="Post to Digg">Digg This Post</a> <a class="tt" href="http://www.facebook.com/share.php?u=http://jasonseifer.com/2009/04/24/receving-email-with-rails&amp;t=Receiving+Email+with+Rails" title="Post to Facebook"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-facebook.png" alt="Post to Facebook" /></a> <a class="tt" href="http://www.facebook.com/share.php?u=http://jasonseifer.com/2009/04/24/receving-email-with-rails&amp;t=Receiving+Email+with+Rails" title="Post to Facebook">Facebook</a> <a class="tt" href="http://reddit.com/submit?url=http://jasonseifer.com/2009/04/24/receving-email-with-rails&amp;title=Receiving+Email+with+Rails" title="Post to Reddit"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-reddit.png" alt="Post to Reddit" /></a> <a class="tt" href="http://reddit.com/submit?url=http://jasonseifer.com/2009/04/24/receving-email-with-rails&amp;title=Receiving+Email+with+Rails" title="Post to Reddit">Reddit This Post</a></p>

<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://jasonseifer.com/2009/04/24/receving-email-with-rails/feed</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>32 Rack Resources to Get You Started</title>
		<link>http://jasonseifer.com/2009/04/08/32-rack-resources-to-get-you-started</link>
		<comments>http://jasonseifer.com/2009/04/08/32-rack-resources-to-get-you-started#comments</comments>
		<pubDate>Wed, 08 Apr 2009 02:47:47 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://jasonseifer.com/?p=174</guid>
		<description><![CDATA[Rack What the heck is Rack and why is it getting so much press lately? Well, from it&#8217;s tag-line: &#8220;Rack provides an minimal interface between webservers supporting Ruby and Ruby frameworks.&#8221; But what does that mean? Prior to Rack if you wanted to interface with Mongrel or Thin you had to write your own custom [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p><img src="http://jasonseifer.com/assets/2009/04/257dcd94-fdec-4a09-b58f-afd97e3f8d3b.jpg" alt="257DCD94-FDEC-4A09-B58F-AFD97E3F8D3B.jpg" border="0" width="400" height="200" align="right" /></p>
<h2>Rack</h2>
<p>
What the heck is Rack and why is it getting so much press lately? Well, from it&#8217;s tag-line: &#8220;Rack provides an minimal interface between webservers supporting Ruby and Ruby frameworks.&#8221;
</p>
<p>But what does that mean?  Prior to Rack if you wanted to interface with Mongrel or Thin you had to write your own custom wrapper for talking to that web server.  Rack standardized the interface for doing that and even added some icing on the cake.</p>
<h3>Resources</h3>
<p></p>
<ul>
<li><a href="http://rack.rubyforge.org/">Rack Homepage</a> &#8211; This is the official Rack home page. There&#8217;s a mirror on <a href="http://rack.github.com">GitHub</a> as well.</li>
<li><a href="http://github.com/rack/rack/tree/master">Rack on GitHub</a> &#8211; This is the official Rack source repository.</li>
<li><a href="http://github.com/rack/rack-contrib/tree/master">Rack-Contrib</a> &#8211; This is the repository for rack middleware and different rack utilities.  It&#8217;s a great starting point for examples.</li>
<li><a href="http://groups.google.com/group/rack-devel">Rack-development</a> &#8211; The official Rack Google Group.  It&#8217;s a great place to ask questions or get help with Rack related troubles.</li>
<li><a href="http://github.com/brynary/rack-test/tree/master">Rack::Test</a> and its <a href="http://gitrdoc.com/brynary/rack-test/tree/master">RDoc</a>.  Much like Rack is a standard interface for talking to web servers, Rack::Test is a standard interface for testing Rack apps.</li>
</ul>
<h3>Tutorials and Links</h3>
<p></p>
<ul>
<li><a href="http://chneukirchen.org/blog/archive/2007/02/introducing-rack.html">Introducing Rack</a> by Christian Neukirchen.  Christian is the author rack and this is the introductory blog post about it.</li>
<li><a href="http://amberbit.com/blog/2009/04/04/introduction-to-rack-middleware/">Introduction to Rack Middleware</a> &#8211; This tutorial goes through what Rack middleware is and gives an example of writing an ascii shrimp middleware in your application.</li>
<li><a href="http://www.decodeuri.com/2008/10/15/creating-a-rack-middleware-for-minifying-your-javascript-files/">Creating a Rack middleware for minifying your javascript files</a> &#8211; This post by Luciano Panaro is less of a tutorial than a full fledged middleware with explanation but it is a solid example to learn from.</li>
<li><a href="http://www.hokstad.com/rack-middleware-adding-cache-headers.html">Adding cache headers</a> by Vidar Hokstad is another example of creating a middleware for a specific purpose.</a></li>
<li><a href="http://asciicasts.com/episodes/151-rack-middleware">Rack middleware asciicast</a> the same version of the RailsCast below but in text form.</li>
<li><a href="http://vision-media.ca/resources/ruby/ruby-rack-middleware-tutorial">Ruby Rack Middleware Tutorial</a> &#8211; This tutorial goes over the call chain and gives a real world example.</li>
<li><a href="http://thewebfellas.com/blog/2008/12/22/flash-uploaders-rails-cookie-based-sessions-and-csrf-rack-middleware-to-the-rescue">Flash uploaders, Rails, cookie based sessions and CSRF: Rack Middleware to the rescue!</a> &#8211; This is one of the better tutorials out there because it starts with a real world problem and demonstrates how to solve it.</li>
<li><a href="http://www.pathf.com/blogs/2009/02/its-only-rack-on-rails-but-i-like-it/">It’s Only Rack on Rails But I Like It</a> &#8211; Noel Rappin goes through and gives a brief introduction to Rack, why it&#8217;s good for Rails, and how to use it from a Rails app.</li>
<li><a href="http://snippets.aktagon.com/snippets/302-How-to-setup-and-use-Rack-Cache-with-Rails-2-3-0-RC-1">How to setup and use Rack::Cache with Rails 2.3</a> &#8211; The title is pretty self explanatory.</li>
<li><a href="http://www.brynary.com/2009/3/5/rack-test-released-a-simple-testing-api-for-rack-based-frameworks-and-apps">Rack::Test tutorial</a> &#8211; Simply test any Rack-compatible app.</li>
<li><a href="http://soylentfoo.jnewland.com/articles/2008/12/16/rails-metal-a-micro-framework-with-the-power-of-rails-m">Rails Metal introduction</a> is an awesome introduction to Rails Metal by Jesse Newland.</li>
<li><a href="http://opensoul.org/2009/3/3/plugging-rack-into-rails">Plugging Rack into Rails</a> &#8211; Another rack/rails tutorial.</li>
<li><a href="http://wiki.github.com/rack/rack/tutorial-rackup-howto">How to Rackup</a> &#8211; This is from the official Rack wiki and explains what Rackup files are and hwo to use them.</li>
</ul>
<h3>Screencasts, Videos, and Presentations</h3>
<p></p>
<ul>
<li><a href="http://wiki.github.com/rack/rack/presentations">Rack presentations</a> on the Rack GitHub wiki.</a></li>
<li><a href="http://mwrc2009.confreaks.com/13-mar-2009-11-05-in-a-world-of-middleware-who-needs-monolithic-applications-jon-crosby.html">Jon Crosby&#8217;s MountainWest Ruby Conf presentaiton</a> &#8211; In a world of middleware, who needs monolithic applications?
<li><a href="http://railscasts.com/episodes/151-rack-middleware">Rack middleware RailsCast</a> &#8211; Ryan Bates usual high quality screencasts on how to create a Rack Middleware</li>
<li><a href="http://railscasts.com/episodes/150-rails-metal">Rails Metal RailsCast</a> &#8211; An introduction to creating Rails Metal apps by Ryan Bates
<li><a href="http://remi.org/2009/02/19/rack-basics.html">Rack basics</a> &#8211; Remi goes in to the very basics of Rack.</li>
<li><a href="http://remi.org/2009/02/24/rack-part-2.html">Rack part 2</a> &#8211; Going over rackup files, creating an executable rack application, using middleware, reloading</a></li>
<li><a href="http://remi.org/2009/02/28/rack-part-3-middleware.html">Rack Middleware</a> &#8211; What it is, how to write your own, using it in Sinatra and Rails</li>
</li>
<li><a href="http://www.techscreencast.com/web-development/ruby-on-rails/rack-middleware/1540">Another Rack middleware screencast</a></li>
</ul>
<h3>Middleware</h3>
<p></p>
<ul>
<li><a href="http://wiki.github.com/rack/rack/list-of-middleware">List of Rack Middleware</a> on the Rack wiki</a>.</li>
<li><a href="http://tomayko.com/src/rack-cache/">Rack-Cache</a> &#8211; HTTP reverse proxy cache (<a href="http://groups.google.com/group/rack-cache/topics">Google Group</a>).    If you want to explore using HTTP caching to its fullest check out this link.  It has a few links that explain HTTP caching as well.</li>
<li><a href="http://github.com/peburrows/rack-contrib/blob/fea3d5b2c23cc5f9337555df9133da3c453fb23f/lib/rack/contrib/cssvariables.rb">CSS Variables</a> and a <a href="http://blog.philburrows.com/articles/2009/03/18/css-variables-with-rack-middleware/">tutorial</a> for using it.</li>
<li><a href="http://github.com/atmos/hancock-client/tree/master">Hancock-client</a> is a sinatra app and rack middleware piece for the hancock SSO server.</li>
</ul>
<h3>Documentation</h3>
<p></p>
<ul>
<li><a href="http://guides.rubyonrails.org/rails_on_rack.html ">Rails on Rack</a> gives you Rails and Rack specific information.  This was suggested by Hubert Lepicki in the comments.</li>
<li><a href="http://rack.rubyforge.org/doc/">Rack Documentation (RDOC)</a></li>
<li><a href="http://rack.rubyforge.org/doc/files/SPEC.html">Rack Specification</a></li>
</ul>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=32+Rack+Resources+to+Get+You+Started+http://bit.ly/a56Zt" title="Post to Twitter"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-twitter-micro1.png" alt="Post to Twitter" /></a> <a class="tt" href="http://delicious.com/post?url=http://jasonseifer.com/2009/04/08/32-rack-resources-to-get-you-started&amp;title=32+Rack+Resources+to+Get+You+Started" title="Post to Delicious"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-delicious.png" alt="Post to Delicious" /></a> <a class="tt" href="http://delicious.com/post?url=http://jasonseifer.com/2009/04/08/32-rack-resources-to-get-you-started&amp;title=32+Rack+Resources+to+Get+You+Started" title="Post to Delicious">Delicious</a> <a class="tt" href="http://digg.com/submit?url=http://jasonseifer.com/2009/04/08/32-rack-resources-to-get-you-started&amp;title=32+Rack+Resources+to+Get+You+Started" title="Post to Digg"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-digg.png" alt="Post to Digg" /></a> <a class="tt" href="http://digg.com/submit?url=http://jasonseifer.com/2009/04/08/32-rack-resources-to-get-you-started&amp;title=32+Rack+Resources+to+Get+You+Started" title="Post to Digg">Digg This Post</a> <a class="tt" href="http://www.facebook.com/share.php?u=http://jasonseifer.com/2009/04/08/32-rack-resources-to-get-you-started&amp;t=32+Rack+Resources+to+Get+You+Started" title="Post to Facebook"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-facebook.png" alt="Post to Facebook" /></a> <a class="tt" href="http://www.facebook.com/share.php?u=http://jasonseifer.com/2009/04/08/32-rack-resources-to-get-you-started&amp;t=32+Rack+Resources+to+Get+You+Started" title="Post to Facebook">Facebook</a> <a class="tt" href="http://reddit.com/submit?url=http://jasonseifer.com/2009/04/08/32-rack-resources-to-get-you-started&amp;title=32+Rack+Resources+to+Get+You+Started" title="Post to Reddit"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-reddit.png" alt="Post to Reddit" /></a> <a class="tt" href="http://reddit.com/submit?url=http://jasonseifer.com/2009/04/08/32-rack-resources-to-get-you-started&amp;title=32+Rack+Resources+to+Get+You+Started" title="Post to Reddit">Reddit This Post</a></p>

<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://jasonseifer.com/2009/04/08/32-rack-resources-to-get-you-started/feed</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Rails metal call order</title>
		<link>http://jasonseifer.com/2009/04/08/rails-metal-call-order</link>
		<comments>http://jasonseifer.com/2009/04/08/rails-metal-call-order#comments</comments>
		<pubDate>Wed, 08 Apr 2009 02:45:01 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[metal]]></category>
		<category><![CDATA[rack]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://jasonseifer.com/?p=172</guid>
		<description><![CDATA[I was really mystified today trying to figure out how to bump up the response in Rails metal. The default metal generator generates something that looks like the following: I had mistakenly changed it to 500 and didn&#8217;t realize why the app completely broke. It turns out that Rails itself uses a 404 code in [...]


Related posts:<ol><li><a href='http://jasonseifer.com/2010/03/10/rails-date-formats' rel='bookmark' title='Permanent Link: Rails Reminder: DATE_FORMATS'>Rails Reminder: DATE_FORMATS</a> <small>A friend of mine recently asked me about adding time...</small></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>I was really mystified today trying to figure out how to bump up the response in Rails metal.  The default metal generator generates something that looks like the following:
</p>
<p><script src="http://gist.github.com/91599.js"></script></p>
<p>I had mistakenly changed it to 500 and didn&#8217;t realize why the app completely broke. It turns out that Rails itself uses a 404 code in the metal response to go up the call chain to the next metal:</p>
<p><script src="http://gist.github.com/91597.js"></script></p>
<p>So if you want to return from the metal, just send back a 404.</p>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=Rails+metal+call+order+http://bit.ly/2RTXEl" title="Post to Twitter"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-twitter-micro1.png" alt="Post to Twitter" /></a> <a class="tt" href="http://delicious.com/post?url=http://jasonseifer.com/2009/04/08/rails-metal-call-order&amp;title=Rails+metal+call+order" title="Post to Delicious"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-delicious.png" alt="Post to Delicious" /></a> <a class="tt" href="http://delicious.com/post?url=http://jasonseifer.com/2009/04/08/rails-metal-call-order&amp;title=Rails+metal+call+order" title="Post to Delicious">Delicious</a> <a class="tt" href="http://digg.com/submit?url=http://jasonseifer.com/2009/04/08/rails-metal-call-order&amp;title=Rails+metal+call+order" title="Post to Digg"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-digg.png" alt="Post to Digg" /></a> <a class="tt" href="http://digg.com/submit?url=http://jasonseifer.com/2009/04/08/rails-metal-call-order&amp;title=Rails+metal+call+order" title="Post to Digg">Digg This Post</a> <a class="tt" href="http://www.facebook.com/share.php?u=http://jasonseifer.com/2009/04/08/rails-metal-call-order&amp;t=Rails+metal+call+order" title="Post to Facebook"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-facebook.png" alt="Post to Facebook" /></a> <a class="tt" href="http://www.facebook.com/share.php?u=http://jasonseifer.com/2009/04/08/rails-metal-call-order&amp;t=Rails+metal+call+order" title="Post to Facebook">Facebook</a> <a class="tt" href="http://reddit.com/submit?url=http://jasonseifer.com/2009/04/08/rails-metal-call-order&amp;title=Rails+metal+call+order" title="Post to Reddit"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-reddit.png" alt="Post to Reddit" /></a> <a class="tt" href="http://reddit.com/submit?url=http://jasonseifer.com/2009/04/08/rails-metal-call-order&amp;title=Rails+metal+call+order" title="Post to Reddit">Reddit This Post</a></p>

<p>Related posts:<ol><li><a href='http://jasonseifer.com/2010/03/10/rails-date-formats' rel='bookmark' title='Permanent Link: Rails Reminder: DATE_FORMATS'>Rails Reminder: DATE_FORMATS</a> <small>A friend of mine recently asked me about adding time...</small></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://jasonseifer.com/2009/04/08/rails-metal-call-order/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Passenger 2.1.1 and Local Production Environment</title>
		<link>http://jasonseifer.com/2009/03/04/passenger-2-1-1-beta-production-env</link>
		<comments>http://jasonseifer.com/2009/03/04/passenger-2-1-1-beta-production-env#comments</comments>
		<pubDate>Wed, 04 Mar 2009 13:03:26 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[passenger]]></category>

		<guid isPermaLink="false">http://jasonseifer.com/?p=163</guid>
		<description><![CDATA[If you're on the passenger 2.1.1 beta and having problems locally with getting your rails apps to not be in the production environment, read on.


No related posts.]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re on the <a href="http://blog.phusion.nl/2009/03/01/phusion-passenger-211-beta-released-thanks-sponsors/">Passenger 2.1.1 beta</a> and can&#8217;t figure out why your rails app is going in to the production mode, it&#8217;s because it sets the RackEnv environment variable production instead of the RailsEnv variable.  This is fine on rails 2.3+ apps because they are based on Rack but if you have a rails 2.2.2 app or below, you&#8217;ll need the following in your apps passenger site config:</p>
<pre>

&lt;VirtualHost*:80&gt;
  ServerName myserver.local
  DocumentRoot "/myapp/public"
  RackEnv development
  RailsEnv development
  &lt;directory "/myapp/public"&gt;
    Order allow,deny
    Allow from all
  &lt;/directory&gt;
&lt;/VirtualHost&gt;
</pre>
<p></p>
<p><strong>Update:</strong> I thought I should add, based on Hongli Lai&#8217;s response in the comments, that this is with me using the passenger preference pane in Leopard.  That might be the culprit.  Is anyone else seeing this problem?  Let me know in the comments.</p>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=Passenger+2.1.1+and+Local+Production+Environment+http://bit.ly/agVnV" title="Post to Twitter"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-twitter-micro1.png" alt="Post to Twitter" /></a> <a class="tt" href="http://delicious.com/post?url=http://jasonseifer.com/2009/03/04/passenger-2-1-1-beta-production-env&amp;title=Passenger+2.1.1+and+Local+Production+Environment" title="Post to Delicious"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-delicious.png" alt="Post to Delicious" /></a> <a class="tt" href="http://delicious.com/post?url=http://jasonseifer.com/2009/03/04/passenger-2-1-1-beta-production-env&amp;title=Passenger+2.1.1+and+Local+Production+Environment" title="Post to Delicious">Delicious</a> <a class="tt" href="http://digg.com/submit?url=http://jasonseifer.com/2009/03/04/passenger-2-1-1-beta-production-env&amp;title=Passenger+2.1.1+and+Local+Production+Environment" title="Post to Digg"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-digg.png" alt="Post to Digg" /></a> <a class="tt" href="http://digg.com/submit?url=http://jasonseifer.com/2009/03/04/passenger-2-1-1-beta-production-env&amp;title=Passenger+2.1.1+and+Local+Production+Environment" title="Post to Digg">Digg This Post</a> <a class="tt" href="http://www.facebook.com/share.php?u=http://jasonseifer.com/2009/03/04/passenger-2-1-1-beta-production-env&amp;t=Passenger+2.1.1+and+Local+Production+Environment" title="Post to Facebook"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-facebook.png" alt="Post to Facebook" /></a> <a class="tt" href="http://www.facebook.com/share.php?u=http://jasonseifer.com/2009/03/04/passenger-2-1-1-beta-production-env&amp;t=Passenger+2.1.1+and+Local+Production+Environment" title="Post to Facebook">Facebook</a> <a class="tt" href="http://reddit.com/submit?url=http://jasonseifer.com/2009/03/04/passenger-2-1-1-beta-production-env&amp;title=Passenger+2.1.1+and+Local+Production+Environment" title="Post to Reddit"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-reddit.png" alt="Post to Reddit" /></a> <a class="tt" href="http://reddit.com/submit?url=http://jasonseifer.com/2009/03/04/passenger-2-1-1-beta-production-env&amp;title=Passenger+2.1.1+and+Local+Production+Environment" title="Post to Reddit">Reddit This Post</a></p>

<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://jasonseifer.com/2009/03/04/passenger-2-1-1-beta-production-env/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Ruby Hash Trickery</title>
		<link>http://jasonseifer.com/2009/03/03/ruby-hash-trickery</link>
		<comments>http://jasonseifer.com/2009/03/03/ruby-hash-trickery#comments</comments>
		<pubDate>Tue, 03 Mar 2009 20:10:46 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[paste]]></category>

		<guid isPermaLink="false">http://jasonseifer.com/?p=159</guid>
		<description><![CDATA[Ilya Grigorick put up a pretty cool pastie showing a neat hack to make Ruby hashes raise errors with invalid keys: Delicious Digg This Post Facebook Reddit This Post No related posts.


No related posts.]]></description>
			<content:encoded><![CDATA[<p><a href="http://igvita.com">Ilya Grigorick</a> put up a pretty cool <a href="http://pastie.org/406312">pastie</a> showing a neat hack to make Ruby hashes raise errors with invalid keys:<br />
<script src='http://pastie.org/406312.js'></script></p>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=Ruby+Hash+Trickery+http://bit.ly/RDZuU" title="Post to Twitter"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-twitter-micro1.png" alt="Post to Twitter" /></a> <a class="tt" href="http://delicious.com/post?url=http://jasonseifer.com/2009/03/03/ruby-hash-trickery&amp;title=Ruby+Hash+Trickery" title="Post to Delicious"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-delicious.png" alt="Post to Delicious" /></a> <a class="tt" href="http://delicious.com/post?url=http://jasonseifer.com/2009/03/03/ruby-hash-trickery&amp;title=Ruby+Hash+Trickery" title="Post to Delicious">Delicious</a> <a class="tt" href="http://digg.com/submit?url=http://jasonseifer.com/2009/03/03/ruby-hash-trickery&amp;title=Ruby+Hash+Trickery" title="Post to Digg"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-digg.png" alt="Post to Digg" /></a> <a class="tt" href="http://digg.com/submit?url=http://jasonseifer.com/2009/03/03/ruby-hash-trickery&amp;title=Ruby+Hash+Trickery" title="Post to Digg">Digg This Post</a> <a class="tt" href="http://www.facebook.com/share.php?u=http://jasonseifer.com/2009/03/03/ruby-hash-trickery&amp;t=Ruby+Hash+Trickery" title="Post to Facebook"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-facebook.png" alt="Post to Facebook" /></a> <a class="tt" href="http://www.facebook.com/share.php?u=http://jasonseifer.com/2009/03/03/ruby-hash-trickery&amp;t=Ruby+Hash+Trickery" title="Post to Facebook">Facebook</a> <a class="tt" href="http://reddit.com/submit?url=http://jasonseifer.com/2009/03/03/ruby-hash-trickery&amp;title=Ruby+Hash+Trickery" title="Post to Reddit"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-reddit.png" alt="Post to Reddit" /></a> <a class="tt" href="http://reddit.com/submit?url=http://jasonseifer.com/2009/03/03/ruby-hash-trickery&amp;title=Ruby+Hash+Trickery" title="Post to Reddit">Reddit This Post</a></p>

<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://jasonseifer.com/2009/03/03/ruby-hash-trickery/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails Magazine Issue 1</title>
		<link>http://jasonseifer.com/2009/03/01/rails-magazine-issue-1</link>
		<comments>http://jasonseifer.com/2009/03/01/rails-magazine-issue-1#comments</comments>
		<pubDate>Sun, 01 Mar 2009 03:43:47 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://jasonseifer.com/?p=157</guid>
		<description><![CDATA[The first issue of Rails Magazine is out! I&#8217;m super excited because I&#8217;ve got an article in there on receiving email with Rails. Go check it out. I can reproduce the article here after the publication has been out for 30 days so stay tuned for that. Delicious Digg This Post Facebook Reddit This Post [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p><a href="http://railsmagazine.com/issues/1"><img src="http://jasonseifer.com/assets/2009/03/skitched-20090228-223944.jpg" alt="skitched-20090228-223944.jpg" border="0" width="233" height="128" align="right" /></a>The first issue of Rails Magazine is out!  I&#8217;m super excited because I&#8217;ve got an article in there on receiving email with Rails.  Go <a href="http://railsmagazine.com/issues/1">check it out</a>.  I can reproduce the article here after the publication has been out for 30 days so stay tuned for that.</p>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=Rails+Magazine+Issue+1+http://bit.ly/BVSfs" title="Post to Twitter"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-twitter-micro1.png" alt="Post to Twitter" /></a> <a class="tt" href="http://delicious.com/post?url=http://jasonseifer.com/2009/03/01/rails-magazine-issue-1&amp;title=Rails+Magazine+Issue+1" title="Post to Delicious"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-delicious.png" alt="Post to Delicious" /></a> <a class="tt" href="http://delicious.com/post?url=http://jasonseifer.com/2009/03/01/rails-magazine-issue-1&amp;title=Rails+Magazine+Issue+1" title="Post to Delicious">Delicious</a> <a class="tt" href="http://digg.com/submit?url=http://jasonseifer.com/2009/03/01/rails-magazine-issue-1&amp;title=Rails+Magazine+Issue+1" title="Post to Digg"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-digg.png" alt="Post to Digg" /></a> <a class="tt" href="http://digg.com/submit?url=http://jasonseifer.com/2009/03/01/rails-magazine-issue-1&amp;title=Rails+Magazine+Issue+1" title="Post to Digg">Digg This Post</a> <a class="tt" href="http://www.facebook.com/share.php?u=http://jasonseifer.com/2009/03/01/rails-magazine-issue-1&amp;t=Rails+Magazine+Issue+1" title="Post to Facebook"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-facebook.png" alt="Post to Facebook" /></a> <a class="tt" href="http://www.facebook.com/share.php?u=http://jasonseifer.com/2009/03/01/rails-magazine-issue-1&amp;t=Rails+Magazine+Issue+1" title="Post to Facebook">Facebook</a> <a class="tt" href="http://reddit.com/submit?url=http://jasonseifer.com/2009/03/01/rails-magazine-issue-1&amp;title=Rails+Magazine+Issue+1" title="Post to Reddit"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-reddit.png" alt="Post to Reddit" /></a> <a class="tt" href="http://reddit.com/submit?url=http://jasonseifer.com/2009/03/01/rails-magazine-issue-1&amp;title=Rails+Magazine+Issue+1" title="Post to Reddit">Reddit This Post</a></p>

<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://jasonseifer.com/2009/03/01/rails-magazine-issue-1/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ruby Interpreter Comparison</title>
		<link>http://jasonseifer.com/2009/02/28/ruby-interpreter-comparison</link>
		<comments>http://jasonseifer.com/2009/02/28/ruby-interpreter-comparison#comments</comments>
		<pubDate>Sat, 28 Feb 2009 00:41:23 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://jasonseifer.com/?p=150</guid>
		<description><![CDATA[I did a talk at QCon a while back on the different Ruby Virtual Machines. You can check out the presentation the InfoQ web site: Ruby VMs: A Comparison. Delicious Digg This Post Facebook Reddit This Post No related posts.


No related posts.]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.infoq.com/presentations/seifer-ruby-vm-comparison"><img src="http://jasonseifer.com/assets/2009/02/infoq-ruby-vms-a-comparison-1.jpg" alt="InfoQ_ Ruby VMs_ A Comparison-1.jpg" border="0" width="331" height="343"  style="float:right; margin: 6px" /></a>I did a talk at QCon a while back on the different Ruby Virtual Machines.  You can check out the presentation the InfoQ web site: <a href="http://www.infoq.com/presentations/seifer-ruby-vm-comparison">Ruby VMs: A Comparison</a>.</p>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=Ruby+Interpreter+Comparison+http://bit.ly/XF57Q" title="Post to Twitter"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-twitter-micro1.png" alt="Post to Twitter" /></a> <a class="tt" href="http://delicious.com/post?url=http://jasonseifer.com/2009/02/28/ruby-interpreter-comparison&amp;title=Ruby+Interpreter+Comparison" title="Post to Delicious"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-delicious.png" alt="Post to Delicious" /></a> <a class="tt" href="http://delicious.com/post?url=http://jasonseifer.com/2009/02/28/ruby-interpreter-comparison&amp;title=Ruby+Interpreter+Comparison" title="Post to Delicious">Delicious</a> <a class="tt" href="http://digg.com/submit?url=http://jasonseifer.com/2009/02/28/ruby-interpreter-comparison&amp;title=Ruby+Interpreter+Comparison" title="Post to Digg"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-digg.png" alt="Post to Digg" /></a> <a class="tt" href="http://digg.com/submit?url=http://jasonseifer.com/2009/02/28/ruby-interpreter-comparison&amp;title=Ruby+Interpreter+Comparison" title="Post to Digg">Digg This Post</a> <a class="tt" href="http://www.facebook.com/share.php?u=http://jasonseifer.com/2009/02/28/ruby-interpreter-comparison&amp;t=Ruby+Interpreter+Comparison" title="Post to Facebook"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-facebook.png" alt="Post to Facebook" /></a> <a class="tt" href="http://www.facebook.com/share.php?u=http://jasonseifer.com/2009/02/28/ruby-interpreter-comparison&amp;t=Ruby+Interpreter+Comparison" title="Post to Facebook">Facebook</a> <a class="tt" href="http://reddit.com/submit?url=http://jasonseifer.com/2009/02/28/ruby-interpreter-comparison&amp;title=Ruby+Interpreter+Comparison" title="Post to Reddit"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-reddit.png" alt="Post to Reddit" /></a> <a class="tt" href="http://reddit.com/submit?url=http://jasonseifer.com/2009/02/28/ruby-interpreter-comparison&amp;title=Ruby+Interpreter+Comparison" title="Post to Reddit">Reddit This Post</a></p>

<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://jasonseifer.com/2009/02/28/ruby-interpreter-comparison/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Offline Gem Server RDocs</title>
		<link>http://jasonseifer.com/2009/02/22/offline-gem-server-rdocs</link>
		<comments>http://jasonseifer.com/2009/02/22/offline-gem-server-rdocs#comments</comments>
		<pubDate>Sun, 22 Feb 2009 07:17:55 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://jasonseifer.com/?p=129</guid>
		<description><![CDATA[ol li { margin: 15px 0 10px 0 } Click To Zoom Get Sinatra, Rubygems, and Passenger working for offline RDocs? Count me in. I saw this and new I had to have it. I&#8217;ve been on some long plane rides recently and I frequently find myself wanting to look up something from a gem&#8217;s [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<style type="text/css">
 ol li { margin: 15px 0 10px 0 }
</style>
<div style="text-align:center;"><a href="http://twitter.com/jnewland/status/1235806122"><img src="http://jasonseifer.com/assets/2009/02/twitter-jesse-newland-sinatra-rubygems-passeng.jpg" alt="Twitter _ Jesse Newland_ sinatra-rubygems + Passeng ....jpg" border="0" width="557" height="232" /></a></div>
<p><div style="text-align:center;float:right;"><a href="http://jasonseifer.com/assets/2009/02/rdoc-documentation.jpg" target="_blank"><img src="http://jasonseifer.com/assets/2009/02/rdoc-documentation-300x206.jpg" alt="RDoc Documentation.jpg" border="0"  /><br/><small>Click To Zoom</small></a></div>
<p>Get Sinatra, Rubygems, and Passenger working for offline RDocs? Count me in.  I saw this and new I had to have it.  I&#8217;ve been on some long plane rides recently and I frequently find myself wanting to look up something from a gem&#8217;s documentation while I&#8217;m coding. You can use the <code>gem server</code> command but that&#8217;s just such a pain to do every time you want to look something up.  I hadn&#8217;t really given it much thought that there might be an easier way until I saw Jesse&#8217;s tweet about it.  Having this offline using passenger at http://gems.local is great but I wanted to have a little more searching baked in.  Here&#8217;s how I did it:
</p>
<ol>
<li><strong>Install the hanna gem from mislav.</strong>
<p> You may need to have the HAML gem installed for this to work.  The hanna gem is a great theme for rdoc output.  It includes javascript to make some ajaxy type search so you can filter methods by typing in to a text field in one of the frames on the left.  It took me a little while to find this theme.  It&#8217;s the one currently in use on <a href="http://gitrdoc.com">GitRDoc</a>, which is a great resource (if you&#8217;re online).</p>
<p>
<script src="http://gist.github.com/68367.js"></script></li>
<li><strong>Tell rdoc to use the hanna theme</strong>
<p>In order to tell rdoc and gem to use this when you use the &quot;gem&quot; command, you need to add to your .gemrc.  Beware that this will affect all future rdoc generation when you install a gem.  Add the following to ~/.gemrc:<br />
<script src="http://gist.github.com/68377.js"></script>
</p>
<p></li>
<li><strong>Regenerate your rdocs</strong>
<p>You then need to regenerate all of your rdocs with this theme.  You can do this by executing the following:<br />
<script src="http://gist.github.com/68378.js"></script>
</p>
<p></li>
<li><strong>Get sinatra-rubygems</strong>
<p>Clone <a href="http://github.com/jseifer/sinatra-rubygems/tree/master">my fork</a> of <a href="http://github.com/jnewland/sinatra-rubygems/tree/master">Jesse Newland&#8217;s sinatra-rubygems</a> from GitHub:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">git clone git:<span style="color: #000000; font-weight: bold;">//</span>github.com<span style="color: #000000; font-weight: bold;">/</span>jseifer<span style="color: #000000; font-weight: bold;">/</span>sinatra-rubygems.git</pre></div></div>

</p>
<p>
</li>
<li><strong>Add it to Passenger</strong>
<p>Hook it up to your <a href="http://www.fngtps.com/2008/06/putting-the-pane-back-into-deployment">passenger preference pane</a> and set the name to &quot;gems.local&quot;, restart Apache and you&#8217;ll be all set:</p>
<div style="text-align:center;"><img src="http://jasonseifer.com/assets/2009/02/passenger-pref-pane.jpg" alt="passenger pref pane.jpg" border="0" width="460" height="339" /></div>
</li>
</ol>
<p>After you complete the above steps, everything should be working.  Enjoy!  This will come in handy next time you don&#8217;t have internet access and need to look up some methods.  I&#8217;d like to give a special thanks to <a href="http://jnewland.com">Jesse Newland</a> for releasing the sinatra-rubygems app.</p>
<p><strong>Update:</strong> k776 points out in the comments that this doesn&#8217;t work on the latest version of rdoc, which is 2.4.1 as of this writing.  It seems 2.3.0 is the version to go with.</p>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=Offline+Gem+Server+RDocs+http://bit.ly/18CRXX" title="Post to Twitter"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-twitter-micro1.png" alt="Post to Twitter" /></a> <a class="tt" href="http://delicious.com/post?url=http://jasonseifer.com/2009/02/22/offline-gem-server-rdocs&amp;title=Offline+Gem+Server+RDocs" title="Post to Delicious"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-delicious.png" alt="Post to Delicious" /></a> <a class="tt" href="http://delicious.com/post?url=http://jasonseifer.com/2009/02/22/offline-gem-server-rdocs&amp;title=Offline+Gem+Server+RDocs" title="Post to Delicious">Delicious</a> <a class="tt" href="http://digg.com/submit?url=http://jasonseifer.com/2009/02/22/offline-gem-server-rdocs&amp;title=Offline+Gem+Server+RDocs" title="Post to Digg"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-digg.png" alt="Post to Digg" /></a> <a class="tt" href="http://digg.com/submit?url=http://jasonseifer.com/2009/02/22/offline-gem-server-rdocs&amp;title=Offline+Gem+Server+RDocs" title="Post to Digg">Digg This Post</a> <a class="tt" href="http://www.facebook.com/share.php?u=http://jasonseifer.com/2009/02/22/offline-gem-server-rdocs&amp;t=Offline+Gem+Server+RDocs" title="Post to Facebook"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-facebook.png" alt="Post to Facebook" /></a> <a class="tt" href="http://www.facebook.com/share.php?u=http://jasonseifer.com/2009/02/22/offline-gem-server-rdocs&amp;t=Offline+Gem+Server+RDocs" title="Post to Facebook">Facebook</a> <a class="tt" href="http://reddit.com/submit?url=http://jasonseifer.com/2009/02/22/offline-gem-server-rdocs&amp;title=Offline+Gem+Server+RDocs" title="Post to Reddit"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-reddit.png" alt="Post to Reddit" /></a> <a class="tt" href="http://reddit.com/submit?url=http://jasonseifer.com/2009/02/22/offline-gem-server-rdocs&amp;title=Offline+Gem+Server+RDocs" title="Post to Reddit">Reddit This Post</a></p>

<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://jasonseifer.com/2009/02/22/offline-gem-server-rdocs/feed</wfw:commentRss>
		<slash:comments>30</slash:comments>
		</item>
		<item>
		<title>Turning Off Webrat&#8217;s Automatic Browser Opening</title>
		<link>http://jasonseifer.com/2009/02/18/turning-off-webrats-automatic-browser-opening</link>
		<comments>http://jasonseifer.com/2009/02/18/turning-off-webrats-automatic-browser-opening#comments</comments>
		<pubDate>Wed, 18 Feb 2009 14:36:36 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://jasonseifer.com/?p=121</guid>
		<description><![CDATA[If you&#8217;re using webrat for doing your integration testing with Rails and you&#8217;re on OS X you may notice that webrat opens an html version of the failing test every time you run it. This can be fairly annoying if you&#8217;re running autotest. I didn&#8217;t see how to turn it off in the documentation but [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re using <a href="http://github.com/brynary/webrat/tree/master">webrat</a> for doing your integration testing with Rails and you&#8217;re on OS X you may notice that webrat opens an html version of the failing test <strong>every time you run it</strong>.  This can be fairly annoying if you&#8217;re running autotest.  I didn&#8217;t see how to turn it off in the documentation but I found on <a href="http://blog.bitmacro.com/2008/11/14/shoulda-factory_girl-webrat">this page</a> that you can turn it off by doing the following:</p>
<p><script src="http://gist.github.com/66362.js"></script></p>
<p>This doesn&#8217;t work for the gem version I had installed but only with the GitHub version of brynary-webrat.</p>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=Turning+Off+Webrat%E2%80%99s+Automatic+Browser+Opening+http://bit.ly/15nXn8" title="Post to Twitter"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-twitter-micro1.png" alt="Post to Twitter" /></a> <a class="tt" href="http://delicious.com/post?url=http://jasonseifer.com/2009/02/18/turning-off-webrats-automatic-browser-opening&amp;title=Turning+Off+Webrat%E2%80%99s+Automatic+Browser+Opening" title="Post to Delicious"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-delicious.png" alt="Post to Delicious" /></a> <a class="tt" href="http://delicious.com/post?url=http://jasonseifer.com/2009/02/18/turning-off-webrats-automatic-browser-opening&amp;title=Turning+Off+Webrat%E2%80%99s+Automatic+Browser+Opening" title="Post to Delicious">Delicious</a> <a class="tt" href="http://digg.com/submit?url=http://jasonseifer.com/2009/02/18/turning-off-webrats-automatic-browser-opening&amp;title=Turning+Off+Webrat%E2%80%99s+Automatic+Browser+Opening" title="Post to Digg"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-digg.png" alt="Post to Digg" /></a> <a class="tt" href="http://digg.com/submit?url=http://jasonseifer.com/2009/02/18/turning-off-webrats-automatic-browser-opening&amp;title=Turning+Off+Webrat%E2%80%99s+Automatic+Browser+Opening" title="Post to Digg">Digg This Post</a> <a class="tt" href="http://www.facebook.com/share.php?u=http://jasonseifer.com/2009/02/18/turning-off-webrats-automatic-browser-opening&amp;t=Turning+Off+Webrat%E2%80%99s+Automatic+Browser+Opening" title="Post to Facebook"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-facebook.png" alt="Post to Facebook" /></a> <a class="tt" href="http://www.facebook.com/share.php?u=http://jasonseifer.com/2009/02/18/turning-off-webrats-automatic-browser-opening&amp;t=Turning+Off+Webrat%E2%80%99s+Automatic+Browser+Opening" title="Post to Facebook">Facebook</a> <a class="tt" href="http://reddit.com/submit?url=http://jasonseifer.com/2009/02/18/turning-off-webrats-automatic-browser-opening&amp;title=Turning+Off+Webrat%E2%80%99s+Automatic+Browser+Opening" title="Post to Reddit"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-reddit.png" alt="Post to Reddit" /></a> <a class="tt" href="http://reddit.com/submit?url=http://jasonseifer.com/2009/02/18/turning-off-webrats-automatic-browser-opening&amp;title=Turning+Off+Webrat%E2%80%99s+Automatic+Browser+Opening" title="Post to Reddit">Reddit This Post</a></p>

<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://jasonseifer.com/2009/02/18/turning-off-webrats-automatic-browser-opening/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mepisto to WordPress Converter</title>
		<link>http://jasonseifer.com/2009/01/11/mepisto-to-wordpress</link>
		<comments>http://jasonseifer.com/2009/01/11/mepisto-to-wordpress#comments</comments>
		<pubDate>Sun, 11 Jan 2009 00:46:47 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[mephisto]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://jasonseifer.com/?p=102</guid>
		<description><![CDATA[As a recent experiment, I tried converting a blog from Mephisto to WordPress. After some quick Googling, I found out that Jason Gill had already largely solved the problem. Unfortunately, his solution didn&#8217;t completely work for me because I didn&#8217;t want to launch Mephisto to do it and I have an aversion with that much [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p>As a recent experiment, I tried converting a blog from Mephisto to WordPress. After some quick Googling, I found out that <a href="http://blog.gilluminate.com/2008/05/08/how-i-converted-mephisto-to-wordpress/">Jason Gill</a> had already largely solved the problem.</p>
<p>Unfortunately, his solution didn&#8217;t completely work for me because I didn&#8217;t want to launch Mephisto to do it and I have an aversion with that much code in a controller. Even if it&#8217;s just going to be run once. Even if it&#8217;s just locally. I know, I have a problem. Anyway, I wanted to launch it from the command line also.</p>
<p>I had been planning to move the <a href="http://railsenvy.com">Rails Envy</a> blog to a different server and saw this as a good opportunity. The plan was to migrate the blog offline and put it on a separate subdomain (something like omgbeta.railsenvy.com). Once everything is totally working, I&#8217;d just point the main dns over. This is a fairly good strategy regardless of the application (blog, app, etc). First, though, I had to get that script working. Here&#8217;s what I came up with:</p>
<p><span><script src="http://gist.github.com/45760.js"></script></span></p>
<p></p>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=Mepisto+to+WordPress+Converter+http://bit.ly/6IjYx" title="Post to Twitter"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-twitter-micro1.png" alt="Post to Twitter" /></a> <a class="tt" href="http://delicious.com/post?url=http://jasonseifer.com/2009/01/11/mepisto-to-wordpress&amp;title=Mepisto+to+WordPress+Converter" title="Post to Delicious"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-delicious.png" alt="Post to Delicious" /></a> <a class="tt" href="http://delicious.com/post?url=http://jasonseifer.com/2009/01/11/mepisto-to-wordpress&amp;title=Mepisto+to+WordPress+Converter" title="Post to Delicious">Delicious</a> <a class="tt" href="http://digg.com/submit?url=http://jasonseifer.com/2009/01/11/mepisto-to-wordpress&amp;title=Mepisto+to+WordPress+Converter" title="Post to Digg"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-digg.png" alt="Post to Digg" /></a> <a class="tt" href="http://digg.com/submit?url=http://jasonseifer.com/2009/01/11/mepisto-to-wordpress&amp;title=Mepisto+to+WordPress+Converter" title="Post to Digg">Digg This Post</a> <a class="tt" href="http://www.facebook.com/share.php?u=http://jasonseifer.com/2009/01/11/mepisto-to-wordpress&amp;t=Mepisto+to+WordPress+Converter" title="Post to Facebook"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-facebook.png" alt="Post to Facebook" /></a> <a class="tt" href="http://www.facebook.com/share.php?u=http://jasonseifer.com/2009/01/11/mepisto-to-wordpress&amp;t=Mepisto+to+WordPress+Converter" title="Post to Facebook">Facebook</a> <a class="tt" href="http://reddit.com/submit?url=http://jasonseifer.com/2009/01/11/mepisto-to-wordpress&amp;title=Mepisto+to+WordPress+Converter" title="Post to Reddit"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-reddit.png" alt="Post to Reddit" /></a> <a class="tt" href="http://reddit.com/submit?url=http://jasonseifer.com/2009/01/11/mepisto-to-wordpress&amp;title=Mepisto+to+WordPress+Converter" title="Post to Reddit">Reddit This Post</a></p>

<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://jasonseifer.com/2009/01/11/mepisto-to-wordpress/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Leopard LoadError: no such file to load &#8212; sqlite3</title>
		<link>http://jasonseifer.com/2008/11/24/leopard-sqlite3-loaderror</link>
		<comments>http://jasonseifer.com/2008/11/24/leopard-sqlite3-loaderror#comments</comments>
		<pubDate>Mon, 24 Nov 2008 09:39:51 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://jasonseifer.com/?p=59</guid>
		<description><![CDATA[I&#8217;m not quite sure why this happened, but I kept getting this error with Leopard and sqlite3: LoadError: no such file to load -- sqlite3 I tried to gem install and uninstall sqlite3-ruby a few times but that didn&#8217;t work out. However, installing from source did. Head on over to the Rubyforge page and download [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m not quite sure why this happened, but I kept getting this error with Leopard and sqlite3:</p>
<p><code>LoadError: no such file to load -- sqlite3</code></p>
<p>I tried to gem install and uninstall sqlite3-ruby a few times but that didn&#8217;t work out. However, installing from source did.  Head on over to the <a href="http://rubyforge.org/projects/sqlite-ruby">Rubyforge page</a> and download the zip or tgz archive.  Extract it and just run:</p>
<p><code>ruby setup.rb</code></p>
<p>After that requiring sqlite3 should work fine.</p>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=Leopard+LoadError%3A+no+such+file+to+load+%E2%80%94+sqlite3+http://bit.ly/4YobT" title="Post to Twitter"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-twitter-micro1.png" alt="Post to Twitter" /></a> <a class="tt" href="http://delicious.com/post?url=http://jasonseifer.com/2008/11/24/leopard-sqlite3-loaderror&amp;title=Leopard+LoadError%3A+no+such+file+to+load+%E2%80%94+sqlite3" title="Post to Delicious"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-delicious.png" alt="Post to Delicious" /></a> <a class="tt" href="http://delicious.com/post?url=http://jasonseifer.com/2008/11/24/leopard-sqlite3-loaderror&amp;title=Leopard+LoadError%3A+no+such+file+to+load+%E2%80%94+sqlite3" title="Post to Delicious">Delicious</a> <a class="tt" href="http://digg.com/submit?url=http://jasonseifer.com/2008/11/24/leopard-sqlite3-loaderror&amp;title=Leopard+LoadError%3A+no+such+file+to+load+%E2%80%94+sqlite3" title="Post to Digg"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-digg.png" alt="Post to Digg" /></a> <a class="tt" href="http://digg.com/submit?url=http://jasonseifer.com/2008/11/24/leopard-sqlite3-loaderror&amp;title=Leopard+LoadError%3A+no+such+file+to+load+%E2%80%94+sqlite3" title="Post to Digg">Digg This Post</a> <a class="tt" href="http://www.facebook.com/share.php?u=http://jasonseifer.com/2008/11/24/leopard-sqlite3-loaderror&amp;t=Leopard+LoadError%3A+no+such+file+to+load+%E2%80%94+sqlite3" title="Post to Facebook"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-facebook.png" alt="Post to Facebook" /></a> <a class="tt" href="http://www.facebook.com/share.php?u=http://jasonseifer.com/2008/11/24/leopard-sqlite3-loaderror&amp;t=Leopard+LoadError%3A+no+such+file+to+load+%E2%80%94+sqlite3" title="Post to Facebook">Facebook</a> <a class="tt" href="http://reddit.com/submit?url=http://jasonseifer.com/2008/11/24/leopard-sqlite3-loaderror&amp;title=Leopard+LoadError%3A+no+such+file+to+load+%E2%80%94+sqlite3" title="Post to Reddit"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-reddit.png" alt="Post to Reddit" /></a> <a class="tt" href="http://reddit.com/submit?url=http://jasonseifer.com/2008/11/24/leopard-sqlite3-loaderror&amp;title=Leopard+LoadError%3A+no+such+file+to+load+%E2%80%94+sqlite3" title="Post to Reddit">Reddit This Post</a></p>

<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://jasonseifer.com/2008/11/24/leopard-sqlite3-loaderror/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Innovation in Ruby</title>
		<link>http://jasonseifer.com/2008/08/08/innovation-in-ruby</link>
		<comments>http://jasonseifer.com/2008/08/08/innovation-in-ruby#comments</comments>
		<pubDate>Fri, 08 Aug 2008 15:49:34 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://jasonseifer.com/?p=41</guid>
		<description><![CDATA[Just got done doing a presentation with Gregg Pollack at the Ruby Hoedown. The talk was on Innovation in Ruby in the last year. You can grab a cheat sheet over on the Rails Envy web site. Delicious Digg This Post Facebook Reddit This Post No related posts.


No related posts.]]></description>
			<content:encoded><![CDATA[<p>Just got done doing a presentation with Gregg Pollack at the <a href="http://www.rubyhoedown.com">Ruby Hoedown</a>.  The talk was on Innovation in Ruby in the last year.  You can grab a <a href="http://railsenvy.com/hoedown">cheat sheet</a> over on the <a href="http://www.railsenvy.com">Rails Envy</a> web site.</p>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=Innovation+in+Ruby+http://bit.ly/15Hqce" title="Post to Twitter"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-twitter-micro1.png" alt="Post to Twitter" /></a> <a class="tt" href="http://delicious.com/post?url=http://jasonseifer.com/2008/08/08/innovation-in-ruby&amp;title=Innovation+in+Ruby" title="Post to Delicious"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-delicious.png" alt="Post to Delicious" /></a> <a class="tt" href="http://delicious.com/post?url=http://jasonseifer.com/2008/08/08/innovation-in-ruby&amp;title=Innovation+in+Ruby" title="Post to Delicious">Delicious</a> <a class="tt" href="http://digg.com/submit?url=http://jasonseifer.com/2008/08/08/innovation-in-ruby&amp;title=Innovation+in+Ruby" title="Post to Digg"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-digg.png" alt="Post to Digg" /></a> <a class="tt" href="http://digg.com/submit?url=http://jasonseifer.com/2008/08/08/innovation-in-ruby&amp;title=Innovation+in+Ruby" title="Post to Digg">Digg This Post</a> <a class="tt" href="http://www.facebook.com/share.php?u=http://jasonseifer.com/2008/08/08/innovation-in-ruby&amp;t=Innovation+in+Ruby" title="Post to Facebook"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-facebook.png" alt="Post to Facebook" /></a> <a class="tt" href="http://www.facebook.com/share.php?u=http://jasonseifer.com/2008/08/08/innovation-in-ruby&amp;t=Innovation+in+Ruby" title="Post to Facebook">Facebook</a> <a class="tt" href="http://reddit.com/submit?url=http://jasonseifer.com/2008/08/08/innovation-in-ruby&amp;title=Innovation+in+Ruby" title="Post to Reddit"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-reddit.png" alt="Post to Reddit" /></a> <a class="tt" href="http://reddit.com/submit?url=http://jasonseifer.com/2008/08/08/innovation-in-ruby&amp;title=Innovation+in+Ruby" title="Post to Reddit">Reddit This Post</a></p>

<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://jasonseifer.com/2008/08/08/innovation-in-ruby/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Backpack Ruby Script</title>
		<link>http://jasonseifer.com/2008/07/22/backpack-ruby-script</link>
		<comments>http://jasonseifer.com/2008/07/22/backpack-ruby-script#comments</comments>
		<pubDate>Tue, 22 Jul 2008 17:47:46 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://jasonseifer.com/?p=37</guid>
		<description><![CDATA[Each week I edit the Rails Envy podcast. We use Backpack to work together on the stories each week. Each story is a note in the Backpack page: Today while I was preparing the post, I remembered that Backpack had an API. A quick google turned up the Backpack API page with a link to [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p>
Each week I edit the <a href="http://www.railsenvy.com">Rails Envy podcast</a>.  We use <a href="http://www.backpackit.com">Backpack</a> to <a href="http://37signals.blogs.com/products/2008/03/rails-envy-team.html">work together</a> on the stories each week.  Each story is a note in the Backpack page:<br />
</p>
<div style="text-align:center"><img src="http://img.skitch.com/20080722-qdrp9t8mu6ea9qaa9y83ynndrp.jpg" /></div>
</p>
<p>Today while I was preparing the post, I remembered that Backpack had an API.  A quick google turned up the <a href="http://developer.37signals.com/backpack/">Backpack API</a> page with a link to the <a href="http://developer.37signals.com/backpack/ruby_wrapper.rb">Ruby wrapper</a>.  About 10 minutes and some regular expressions later I had a script to auto format the weekly podcast links each week by just passing in the page id.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rubygems'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'XmlSimple'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'ruby_wrapper'</span>
&nbsp;
stories = <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span>
backpack = Backpack.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'username'</span>, <span style="color:#996600;">'api key'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;
backpack.<span style="color:#9900CC;">page_id</span>=<span style="color:#996600;">'the page you want'</span>
notes = backpack.<span style="color:#9900CC;">list_notes</span>
notes = notes<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'notes'</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">first</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'note'</span><span style="color:#006600; font-weight:bold;">&#93;</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># {'title' =&gt; 'A note', 'id' =&gt; 'An id', 'content' =&gt; 'asdf followed by a url'}</span>
notes.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>note<span style="color:#006600; font-weight:bold;">|</span>
  story_link = note<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'content'</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">scan</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#40;</span>http\:\<span style="color:#006600; font-weight:bold;">/</span>\<span style="color:#006600; font-weight:bold;">/</span>.<span style="color:#006600; font-weight:bold;">*</span><span style="color:#006600; font-weight:bold;">&#41;</span>$<span style="color:#006600; font-weight:bold;">/</span>m<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span>
  stories.<span style="color:#9900CC;">push</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;&lt;li&gt;&lt;a title=<span style="color:#000099;">\&quot;</span>#{note['title']}<span style="color:#000099;">\&quot;</span> href=<span style="color:#000099;">\&quot;</span>#{story_link}<span style="color:#000099;">\&quot;</span> rel=<span style="color:#000099;">\&quot;</span>nofollow<span style="color:#000099;">\&quot;</span>&gt;#{note['title']}&lt;/a&gt;&lt;/li&gt;&quot;</span>.<span style="color:#CC0066; font-weight:bold;">gsub</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">/</span>\n<span style="color:#006600; font-weight:bold;">/</span>,<span style="color:#996600;">''</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#CC0066; font-weight:bold;">puts</span> stories.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;<span style="color:#000099;">\n</span>&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p align="left"><a class="tt" href="http://twitter.com/home/?status=Backpack+Ruby+Script+http://bit.ly/s9cGf" title="Post to Twitter"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-twitter-micro1.png" alt="Post to Twitter" /></a> <a class="tt" href="http://delicious.com/post?url=http://jasonseifer.com/2008/07/22/backpack-ruby-script&amp;title=Backpack+Ruby+Script" title="Post to Delicious"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-delicious.png" alt="Post to Delicious" /></a> <a class="tt" href="http://delicious.com/post?url=http://jasonseifer.com/2008/07/22/backpack-ruby-script&amp;title=Backpack+Ruby+Script" title="Post to Delicious">Delicious</a> <a class="tt" href="http://digg.com/submit?url=http://jasonseifer.com/2008/07/22/backpack-ruby-script&amp;title=Backpack+Ruby+Script" title="Post to Digg"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-digg.png" alt="Post to Digg" /></a> <a class="tt" href="http://digg.com/submit?url=http://jasonseifer.com/2008/07/22/backpack-ruby-script&amp;title=Backpack+Ruby+Script" title="Post to Digg">Digg This Post</a> <a class="tt" href="http://www.facebook.com/share.php?u=http://jasonseifer.com/2008/07/22/backpack-ruby-script&amp;t=Backpack+Ruby+Script" title="Post to Facebook"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-facebook.png" alt="Post to Facebook" /></a> <a class="tt" href="http://www.facebook.com/share.php?u=http://jasonseifer.com/2008/07/22/backpack-ruby-script&amp;t=Backpack+Ruby+Script" title="Post to Facebook">Facebook</a> <a class="tt" href="http://reddit.com/submit?url=http://jasonseifer.com/2008/07/22/backpack-ruby-script&amp;title=Backpack+Ruby+Script" title="Post to Reddit"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-reddit.png" alt="Post to Reddit" /></a> <a class="tt" href="http://reddit.com/submit?url=http://jasonseifer.com/2008/07/22/backpack-ruby-script&amp;title=Backpack+Ruby+Script" title="Post to Reddit">Reddit This Post</a></p>

<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://jasonseifer.com/2008/07/22/backpack-ruby-script/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Hpricot and utf-8</title>
		<link>http://jasonseifer.com/2008/03/18/hpricot-and-utf-8</link>
		<comments>http://jasonseifer.com/2008/03/18/hpricot-and-utf-8#comments</comments>
		<pubDate>Tue, 18 Mar 2008 18:07:55 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://jasonseifer.com/blog/hpricot-and-utf-8</guid>
		<description><![CDATA[I tried to use Hpricot to parse a page with special characters in a utf-8 encoding. The docs tell you to do this: require 'rubygems' require 'open-uri' require 'hpricot' &#160; doc = Hpricot&#40;open&#40;&#34;http://url/&#34;&#41;&#41; However, this won&#8217;t give you the output you want. The open method on Open-URI leaves the output in the default character set [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p>I tried to use <a hfef="http://code.whytheluckystiff.net/hpricot/">Hpricot</a> to parse a page with special characters in a utf-8 encoding.  The docs tell you to do this:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rubygems'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'open-uri'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'hpricot'</span>
&nbsp;
doc = Hpricot<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0066; font-weight:bold;">open</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;http://url/&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>However, this won&#8217;t give you the output you want.  The open method on Open-URI leaves the output in the default character set of the page.  If you want to convert it to utf-8, you need to use the iconv library:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rubygems'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'iconv'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'open-uri'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'hpricot'</span>
&nbsp;
f = <span style="color:#CC0066; font-weight:bold;">open</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;http://url&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
f.<span style="color:#9900CC;">rewind</span>
doc = Hpricot<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">Iconv</span>.<span style="color:#9900CC;">conv</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'utf-8'</span>, f.<span style="color:#9900CC;">charset</span>, f.<span style="color:#CC0066; font-weight:bold;">readlines</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;<span style="color:#000099;">\n</span>&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p align="left"><a class="tt" href="http://twitter.com/home/?status=Hpricot+and+utf-8+http://bit.ly/h2Qqt" title="Post to Twitter"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-twitter-micro1.png" alt="Post to Twitter" /></a> <a class="tt" href="http://delicious.com/post?url=http://jasonseifer.com/2008/03/18/hpricot-and-utf-8&amp;title=Hpricot+and+utf-8" title="Post to Delicious"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-delicious.png" alt="Post to Delicious" /></a> <a class="tt" href="http://delicious.com/post?url=http://jasonseifer.com/2008/03/18/hpricot-and-utf-8&amp;title=Hpricot+and+utf-8" title="Post to Delicious">Delicious</a> <a class="tt" href="http://digg.com/submit?url=http://jasonseifer.com/2008/03/18/hpricot-and-utf-8&amp;title=Hpricot+and+utf-8" title="Post to Digg"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-digg.png" alt="Post to Digg" /></a> <a class="tt" href="http://digg.com/submit?url=http://jasonseifer.com/2008/03/18/hpricot-and-utf-8&amp;title=Hpricot+and+utf-8" title="Post to Digg">Digg This Post</a> <a class="tt" href="http://www.facebook.com/share.php?u=http://jasonseifer.com/2008/03/18/hpricot-and-utf-8&amp;t=Hpricot+and+utf-8" title="Post to Facebook"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-facebook.png" alt="Post to Facebook" /></a> <a class="tt" href="http://www.facebook.com/share.php?u=http://jasonseifer.com/2008/03/18/hpricot-and-utf-8&amp;t=Hpricot+and+utf-8" title="Post to Facebook">Facebook</a> <a class="tt" href="http://reddit.com/submit?url=http://jasonseifer.com/2008/03/18/hpricot-and-utf-8&amp;title=Hpricot+and+utf-8" title="Post to Reddit"><img class="nothumb" src="http://jasonseifer.com/wp-content/plugins/tweet-this/icons/tt-reddit.png" alt="Post to Reddit" /></a> <a class="tt" href="http://reddit.com/submit?url=http://jasonseifer.com/2008/03/18/hpricot-and-utf-8&amp;title=Hpricot+and+utf-8" title="Post to Reddit">Reddit This Post</a></p>

<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://jasonseifer.com/2008/03/18/hpricot-and-utf-8/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>
