<?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>redemption in a blog &#187; Ruby on Rails</title>
	<atom:link href="http://blog.codefront.net/category/ruby-on-rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.codefront.net</link>
	<description>Rails, Firefox, Anime, Mac</description>
	<lastBuildDate>Thu, 04 Feb 2010 14:12:27 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Don&#8217;t kill your app when using ActiveRecord in Rails Metal, release your database connections</title>
		<link>http://blog.codefront.net/2009/06/15/activerecord-rails-metal-too-many-connections/</link>
		<comments>http://blog.codefront.net/2009/06/15/activerecord-rails-metal-too-many-connections/#comments</comments>
		<pubDate>Mon, 15 Jun 2009 06:49:51 +0000</pubDate>
		<dc:creator>Chu Yeow</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://blog.codefront.net/?p=1143</guid>
		<description><![CDATA[Rails Metal has been available on Rails since version 2.3 &#8211; it&#8217;s old news. But if you haven&#8217;t used it or heard about it, you can find out more about Rails Metal on the RoR weblog and on Jesse Newland&#8217;s blog.
So anyway, I am one of those laggards and only wrote a Rails Metal piece [...]]]></description>
			<content:encoded><![CDATA[<p>Rails Metal has been available on Rails since version 2.3 &#8211; it&#8217;s old news. But if you haven&#8217;t used it or heard about it, you can find out more about Rails Metal on the <a href="http://weblog.rubyonrails.org/2008/12/17/introducing-rails-metal">RoR weblog</a> and on <a href="http://soylentfoo.jnewland.com/articles/2008/12/16/rails-metal-a-micro-framework-with-the-power-of-rails-m">Jesse Newland&#8217;s blog</a>.</p>
<p>So anyway, I am one of those laggards and only wrote a Rails Metal piece not too long ago for a Rails app on <a href="http://www.wego.com/">Wego.com</a> in an effort to optimize some high volume requests. It looked something like this:</p>
<pre><code class="ruby">class Adamantine
  def self.call(env)
    if env['PATH_INFO'] =~ ROUTE_REGEX
      location = Location.find(1) # Use ActiveRecord.

      [200, { 'Content-Type' => 'text/html' }, [location.to_json]]
    else
      # Leave it to Rails to deal with the request.
      [404, { 'Content-Type' => 'text/html' }, ['Not Found']]
    end
  end
end</code></pre>
<p>Notice the use of an ActiveRecord model. It ran for quite awhile, almost 30 minutes, in <em>production</em> until I started getting notification emails about &#8220;<strong>Too many open database connections</strong>&#8221; to the MySQL server! The change was promptly rolled back and there was no cheezburger for me.</p>
<p><a href="http://icanhascheezburger.com/2008/04/25/funny-pictures-dam-it-dam-it-dam-it/"><img src="http://icanhascheezburger.wordpress.com/files/2008/04/funny-pictures-beaver-dam-it.jpg" alt="dam it!" /></a></p>
<p>As it turns out, Rails doesn&#8217;t take care of certain things in Rails Metal pieces, including the releasing of connections back to the database connection pool. A bit of googling turned up this <a href="https://rails.lighthouseapp.com/projects/8994/tickets/1882-rails-metal-with-activerecord-too-slow">bug in Rails&#8217; bug tracker</a> (see Josh Peek&#8217;s comment about <code>ActiveRecord::Base.clear_active_connections!</code>).</p>
<p>I rewrote the Rails Metal piece to always ensure it clears any active database connections with <code>ActiveRecord::Base.clear_active_connections!</code>:</p>
<pre><code class="ruby">class Adamantine
  def self.call(env)
    if env['PATH_INFO'] =~ ROUTE_REGEX
      location = Location.find(1)

      [200, { 'Content-Type' => 'text/html' }, [location.to_json]]
    else
      # Leave it to Rails to deal with the request.
      [404, { 'Content-Type' => 'text/html' }, ['Not Found']]
    end
  ensure
    # Release the connections back to the pool.
    ActiveRecord::Base.clear_active_connections!
  end
end</code></pre>
<p>Moral of the story: Don&#8217;t forget to release your database connections if you&#8217;re using ActiveRecord in your Rails Metal. Or even better, don&#8217;t use ActiveRecord in Rails Metal &#8211; you&#8217;re aiming for raw speed anyway right?</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codefront.net/2009/06/15/activerecord-rails-metal-too-many-connections/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Living on the Edge (of Rails) has a new home at the Official Ruby on Rails weblog</title>
		<link>http://blog.codefront.net/2008/06/22/living-on-the-edge-of-rails-has-a-new-home-at-the-official-ruby-on-rails-weblog/</link>
		<comments>http://blog.codefront.net/2008/06/22/living-on-the-edge-of-rails-has-a-new-home-at-the-official-ruby-on-rails-weblog/#comments</comments>
		<pubDate>Sun, 22 Jun 2008 09:55:39 +0000</pubDate>
		<dc:creator>Chu Yeow</dc:creator>
				<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://blog.codefront.net/?p=1123</guid>
		<description><![CDATA[You may have heard of it, but just in case, Living on the Edge is now going to be published on the official Ruby on Rails weblog. Big thanks to Gregg Pollack for getting me the new &#8220;gig&#8221;, and more importantly, for reviving and freshening up the content on the official Rails blog.
Catch the new [...]]]></description>
			<content:encoded><![CDATA[<p>You may have <a href="http://weblog.rubyonrails.org/2008/6/10/two-new-weekly-columns">heard of it</a>, but just in case, <a href="http://blog.codefront.net/category/edge-rails/">Living on the Edge</a> is now going to be published on the <a href="http://weblog.rubyonrails.org/">official Ruby on Rails weblog</a>. Big thanks to <a href="http://railsenvy.com/">Gregg Pollack</a> for getting me the new &#8220;gig&#8221;, and more importantly, for reviving and freshening up the content on the official Rails blog.</p>
<p>Catch the new first edition &#8211; this one&#8217;s about the <a href="http://weblog.rubyonrails.org/2008/6/20/living-on-the-edge-or-what-s-new-in-edge-rails-1-api-changes-and-performancetests">API changes since Rails 2.1</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codefront.net/2008/06/22/living-on-the-edge-of-rails-has-a-new-home-at-the-official-ruby-on-rails-weblog/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>RailsConf 2008 Day 1 &#8211; pics and a summary</title>
		<link>http://blog.codefront.net/2008/05/30/railsconf-2008-day-1-pics-and-a-summary/</link>
		<comments>http://blog.codefront.net/2008/05/30/railsconf-2008-day-1-pics-and-a-summary/#comments</comments>
		<pubDate>Fri, 30 May 2008 05:32:11 +0000</pubDate>
		<dc:creator>Chu Yeow</dc:creator>
				<category><![CDATA[Personal]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://blog.codefront.net/?p=1111</guid>
		<description><![CDATA[Day 1 of RailsConf 2008 was basically tutorial day (schedule) and started with my colleague here with me, Arun, missing out on Yoga on Rails and me sleeping until the first tutorial session. Anyway, I snapped some photos while trying to remain the unobtrusive tourist.
Here&#8217;s a shot of Portland Convention Center where it&#8217;s all happening:


There&#8217;re [...]]]></description>
			<content:encoded><![CDATA[<p>Day 1 of <a href="http://en.oreilly.com/rails2008/public/content/home">RailsConf 2008</a> was basically tutorial day (<a href="http://en.oreilly.com/rails2008/public/schedule/grid?date=2008-05-29">schedule</a>) and started with my colleague here with me, <a href="http://arunthampi.wordpress.com/">Arun</a>, missing out on <a href="http://en.oreilly.com/rails2008/public/schedule/detail/4417">Yoga on Rails</a> and me sleeping until the first tutorial session. Anyway, I snapped some photos while trying to remain the unobtrusive tourist.</p>
<p>Here&#8217;s a shot of Portland Convention Center where it&#8217;s all happening:</p>
<div class="img"><img src="http://blog.codefront.net/wp-content/uploads/2008/05/portland-convention-center-twin-peaks.jpg" alt="Portland Convention Center - twin peaks outside" /></div>
<p><br style="clear: both;" /></p>
<p>There&#8217;re queues for collection of badges after registering your attendance:</p>
<div class="img"><img src="http://blog.codefront.net/wp-content/uploads/2008/05/railsconf-day-1-registration-3.jpg" alt="RailsConf Day 1 - registration queue" /></div>
<p><br style="clear: both;" /></p>
<p>Patience in the queue rewarded me with a RailsConf badge/name tag:</p>
<div class="img"><img src="http://blog.codefront.net/wp-content/uploads/2008/05/railsconf-badge.jpg" alt="RailsConf badge" /></div>
<p><br style="clear: both;" /></p>
<p>I was at the <a href="http://en.oreilly.com/rails2008/public/schedule/detail/1862">Meta-programming Ruby for Fun &amp; Profit</a> tutorial in the morning. I think when I selected the tutorial it was before I&#8217;d seen Neal Ford and Patrick Farley&#8217;s (the speakers) presentation videos from elsewhere &#8211; I know <a href="http://mtnwestrubyconf2008.confreaks.com/11farley.html">Patrick presented at MWRC</a> and enjoyed that video.</p>
<div class="img"><img src="http://blog.codefront.net/wp-content/uploads/2008/05/railsconf-day-1-metaprogramming-tutorial-1.jpg" alt="RailsConf day 1 - metaprogramming tutorial" /></div>
<p><br style="clear: both;" /></p>
<p>So anyway, after the break I went over to the <a href="http://en.oreilly.com/rails2008/public/schedule/detail/1962">Refactoring Your Rails Application</a> tutorial. Was pretty good, but I didn&#8217;t learn much I didn&#8217;t already know.</p>
<p>Lunch came in the form of a pretty box:</p>
<div class="img"><img src="http://blog.codefront.net/wp-content/uploads/2008/05/railsconf-day-1-lunch.jpg" alt="RailsConf day 1 - lunch" /></div>
<p><br style="clear: both;" /></p>
<p>After lunch was the 2nd tutorial session and I went to both <a href="http://en.oreilly.com/rails2008/public/schedule/detail/2072">CI for the Rails Guy (or Gal)</a> (by Chad Woolley) and <a href="http://en.oreilly.com/rails2008/public/schedule/detail/1993">Developer Testing Tricks</a> (by Brian Takita). There were some scathing comments about how the tutorials were rather underwhelming so far in <a href="irc://irc.freenode.net/railsconf">#railsconf</a> on IRC. While I agree that the tutorials were rather underwhelming, I think I should have expected it. Oh well, I&#8217;ll know to skip them next time.</p>
<p>Later that night, at the Birds of a Feather session, after stealing a <a href="http://www.pivotalabs.com/">Pivotal Labs t-shirt</a> (they&#8217;re launching a bug tracker, project management type app called <a href="http://www.pivotaltracker.com/">Pivotal Tracker</a> at RailsConf), Yehuda Katz (Merb and jQuery ninja) gave a presentation on Merb (geared towards Rails folks). It was a pretty interesting talk though there wasn&#8217;t much above what Ezra had <a href="http://goruco2008.confreaks.com/06_zygmuntowicz.html">presented previously at GoRuCo 2008</a> and <a href="http://mwrc2008.confreaks.com/02zygmuntowicz.html">at MWRC 2008</a> (I think Yehuda did one too but I can&#8217;t remember where now). Yehuda pointed out a <a href="http://groups.google.com/group/merb/browse_thread/thread/2536bff7d9195b83">(heated) discussion that happened recently</a> on keeping Merb syntax as Rails-friendly as possible. I have no objection against a different syntax really, especially since Merb looks pretty well-documented in the source itself &#8211; would be nice if someone could point out an up-to-date Merb tutorial though.</p>
<p>Anyway, that&#8217;s it from me &#8211; as always, if anyone who reads my blog <a href="http://www.facebook.com/profile.php?id=500115784">recognizes me</a> at RailsConf, do say hi (<a href="irc://irc.freenode.net/railsconf">#railsconf</a> works too).</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codefront.net/2008/05/30/railsconf-2008-day-1-pics-and-a-summary/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Living on the edge (of Rails) #22 &#8211; pre-Railsconf 2008 edition</title>
		<link>http://blog.codefront.net/2008/05/25/living-on-the-edge-of-rails-22-pre-railsconf-2008-edition/</link>
		<comments>http://blog.codefront.net/2008/05/25/living-on-the-edge-of-rails-22-pre-railsconf-2008-edition/#comments</comments>
		<pubDate>Sun, 25 May 2008 11:06:36 +0000</pubDate>
		<dc:creator>Chu Yeow</dc:creator>
				<category><![CDATA[Edge Rails]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://blog.codefront.net/?p=1110</guid>
		<description><![CDATA[No mind-blowing changes in Rails this week prior to RailsConf &#8211; as Gregg mentioned last week in the Rails Envy podcast, it&#8217;s pre-2.1 days (Rails 2.1 will probably be released at RailsConf) so it&#8217;s pretty easy to see why. Oh and all Rails tests now pass in Ruby 1.9 after a long-standing #module_eval bug got [...]]]></description>
			<content:encoded><![CDATA[<p>No mind-blowing changes in Rails this week prior to RailsConf &#8211; as Gregg mentioned last week in the <a href="http://railsenvy.com/2008/5/21/rails-envy-podcast-episode-032">Rails Envy podcast</a>, it&#8217;s pre-2.1 days (Rails 2.1 will <em>probably</em> be released at RailsConf) so it&#8217;s pretty easy to see why. Oh and all Rails tests now pass in Ruby 1.9 after a long-standing <code>#module_eval</code> bug got fixed in Ruby 1.9&#8217;s trunk (see <a href="http://groups.google.com/group/ruby-core-google/browse_thread/thread/6d08e11363bf49b4">thread</a> for more details).</p>
<p>I&#8217;ll be at (my first) Railsconf 2008 in Portland, Oregon this Thursday onwards &#8211; if anyone sees me and recognizes me from my <a href="http://www.facebook.com/people/Chu_Yeow/500115784">Facebook picture</a> please come and say hi (no head butting though).</p>
<p>This week’s report covers changes from 19th May 2008 to 25th May 2008 (the day the corresponding <a href="http://railsenvy.com/podcast/">Rails Envy podcast</a> was recorded).</p>
<h3>first and last methods now work with associations and named_scope</h3>
<p>Remember how the <a href="http://blog.codefront.net/2008/04/05/living-on-the-edge-of-rails-14-the-extreme-edition-extremely-late/">merging of the has_finder gem into Rails</a> allowed you to do things like <code>Post.first</code> and <code>Post.last</code>?</p>
<p>Now you can go one step further and use the same methods on your ActiveRecord associations. For example:</p>
<pre><code class="ruby">post = Post.find(1)
first_comment = post.comments.first</code></pre>
<p>If you have a <a href="http://ryandaigle.com/articles/2008/3/24/what-s-new-in-edge-rails-has-finder-functionality">named_scope</a> named <code>recent</code> defined, you can even do this:</p>
<pre><code class="ruby">post.comments.recent.last</code></pre>
<p>This neat little enhancement is courtesy of <a href="http://railscasts.com/">Ryan Bates</a> (yes, that <em>Ryan Bates</em> of <a href="http://railscasts.com/">Railscasts</a> fame).</p>
<p>Related changeset: <a href="http://github.com/rails/rails/commit/73c59638549686fccc749ffd3ac53cb533c5fd61">http://github.com/rails/rails/commit/73c59638549686fccc749ffd3ac53cb533c5fd61</a></p>
<h3>Cache stores now have an exist? method and controllers get fragment_exist?</h3>
<p>The cache stores in Rails (Memcache, file stores, etc.) now have an <code>exist?</code> method that checks whether a cached value exists given a cache key. This allows Rails controllers to expose a <code>fragment_exist?<br />
</code> method that allows you to check for existence of a cache fragment:</p>
<pre><code class="ruby">fragment_exist?('example.com/foo/bar')</code></pre>
<p>This little enhancement is courtesy of <a href="http://josevalim.blogspot.com/">José Valim</a>.</p>
<p>Related changeset: <a href="http://github.com/rails/rails/commit/99860b72aebe0348f41e82d4710343498d89a84b#diff-2">http://github.com/rails/rails/commit/99860b72aebe0348f41e82d4710343498d89a84b#diff-2</a></p>
<h3>Create association records with block argument</h3>
<p>You can now create records for associations like so:</p>
<pre><code class="ruby">post.coments.create!(:title => 'Techcrunch') do |c|
  c.body = "Rails can't scale"
end</code></pre>
<p>This is in keeping with the <a href="http://blog.codefront.net/2008/05/04/living-on-the-edge-of-rails-19-change_table-for-migrations-and-more/">ActiveRecord::Base.create change previously mentioned</a>.</p>
<p>Credit for this patch goes (once again) to <a href="http://railscasts.com/">Ryan Bates</a>.</p>
<p>Related changeset: <a href="http://github.com/rails/rails/commit/6cba97d2a449faf21aec9fe9d4434067e414226f">http://github.com/rails/rails/commit/6cba97d2a449faf21aec9fe9d4434067e414226f</a></p>
<p>As always, let me know of any suggestions or how I can improve the Living on the Edge (of Rails) series.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codefront.net/2008/05/25/living-on-the-edge-of-rails-22-pre-railsconf-2008-edition/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Living on the Edge (of Rails) in Spanish</title>
		<link>http://blog.codefront.net/2008/05/18/living-on-the-edge-of-rails-in-spanish/</link>
		<comments>http://blog.codefront.net/2008/05/18/living-on-the-edge-of-rails-in-spanish/#comments</comments>
		<pubDate>Sun, 18 May 2008 12:16:18 +0000</pubDate>
		<dc:creator>Chu Yeow</dc:creator>
				<category><![CDATA[Asides]]></category>
		<category><![CDATA[Edge Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://blog.codefront.net/?p=1109</guid>
		<description><![CDATA[Juan Lupión wrote in to inform me that he&#8217;s also translating my Living on the Edge (of Rails) series of blog posts to Español. Thanks Juan!
]]></description>
			<content:encoded><![CDATA[<p><a href="http://sobrerailes.com/">Juan Lupión</a> wrote in to inform me that he&#8217;s also translating my Living on the Edge (of Rails) series of blog posts to Español. Thanks Juan!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codefront.net/2008/05/18/living-on-the-edge-of-rails-in-spanish/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Living on the edge (of Rails) #21</title>
		<link>http://blog.codefront.net/2008/05/18/living-on-the-edge-of-rails-21/</link>
		<comments>http://blog.codefront.net/2008/05/18/living-on-the-edge-of-rails-21/#comments</comments>
		<pubDate>Sun, 18 May 2008 11:54:42 +0000</pubDate>
		<dc:creator>Chu Yeow</dc:creator>
				<category><![CDATA[Edge Rails]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://blog.codefront.net/?p=1108</guid>
		<description><![CDATA[It&#8217;s another slow week (just 2 changes of note imho) after the release of the 1st Release Candidate (RC1) of Rails 2.1. Follow that link for installation instructions &#8211; though if you&#8217;re reading this blog post you probably don&#8217;t care! (because you&#8217;re, you know, &#8220;living on the edge&#8221;). Cheesiness aside, be sure to report any [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s another slow week (just 2 changes of note <acronym title="in my humble opinion">imho</acronym>) after the <a href="http://www.rubyinside.com/rails-21-released-891.html">release of the 1st Release Candidate (RC1) of Rails 2.1</a>. Follow that link for installation instructions &#8211; though if you&#8217;re reading this blog post you probably don&#8217;t care! (because you&#8217;re, you know, &#8220;living on the edge&#8221;). Cheesiness aside, be sure to report any bugs you may encounter when upgrading to 2.1 RC1 or edge at the <a href="http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/overview">Rails bug tracker</a> &#8211; it is an RC so any bug reports would be very welcome and useful!</p>
<p>This week’s report covers changes from 12th May 2008 to 18th May 2008 (the day the corresponding <a href="http://railsenvy.com/podcast/">Rails Envy podcast</a> was recorded).</p>
<h3>caches_action can has conditionals</h3>
<p><code>caches_action</code> now takes an <code>:if</code> option (just like <a href="http://blog.codefront.net/2008/04/20/living-on-the-edge-of-rails-17/">caches_page does</a>). For example:</p>
<pre><code class="ruby">caches_action :index, :if =&gt; Proc.new { |c| !c.request.format.json? }</code></pre>
<p>This little enhancement is courtesy of José Valim.</p>
<p>Related changeset: <a href="http://github.com/rails/rails/commit/7708650f73ddb4db300ea2059c60c1d907a4384e">http://github.com/rails/rails/commit/7708650f73ddb4db300ea2059c60c1d907a4384e</a></p>
<h3>Bugfix: :select option is now scanned in ActiveRecord finders to ensure needed tables are included in generated SQL</h3>
<pre><code class="ruby">Post.find(:all, :include =&gt; :author, :select =&gt; 'posts.*, authors.id as "author_id"', :limit =&gt; 2)</code></pre>
<p>Would generate an SQL statement like this:</p>
<pre><code class="sql">SELECT posts.*, authors.id as "author_id" FROM "posts" LIMIT 2</code></pre>
<p>Notice how the <code>authors</code> table is not joined. This oversight is now fixed.</p>
<p>Thanks go to John Devine for this bugfix.</p>
<p>Related changeset: <a href="http://github.com/rails/rails/commit/b28b54cab090bed8f099ef375b419a8f92390dd4">http://github.com/rails/rails/commit/b28b54cab090bed8f099ef375b419a8f92390dd4</a></p>
<p>As always, let me know of any suggestions or how I can improve the Living on the Edge (of Rails) series. Also, if anyone has any recommendations of (non-ruby-related) things to do in Portland, do let me know!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codefront.net/2008/05/18/living-on-the-edge-of-rails-21/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Deploying with Capistrano via a gateway &#8211; some notes</title>
		<link>http://blog.codefront.net/2008/05/15/deploying-with-capistrano-via-a-gateway/</link>
		<comments>http://blog.codefront.net/2008/05/15/deploying-with-capistrano-via-a-gateway/#comments</comments>
		<pubDate>Thu, 15 May 2008 09:03:48 +0000</pubDate>
		<dc:creator>Chu Yeow</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://blog.codefront.net/?p=1107</guid>
		<description><![CDATA[Some notes on setting up a gateway server for deploying via Capistrano that I couldn&#8217;t find at the source.

You can specify the user you want to use to login to your gateway server like so: set :gateway, 'deploy@deploy.example.com'. This logs in to your gateway server as the &#8220;deploy&#8221; user.
You can specify an alternate SSH port [...]]]></description>
			<content:encoded><![CDATA[<p>Some notes on setting up a <a href="http://weblog.jamisbuck.org/2006/9/26/inside-capistrano-the-gateway-implementation">gateway server for deploying via Capistrano</a> that I couldn&#8217;t find at <a href="http://capify.org/getting-started/basics">the source</a>.</p>
<ul>
<li>You can specify the user you want to use to login to your gateway server like so: <code>set :gateway, 'deploy@deploy.example.com'</code>. This logs in to your gateway server as the &#8220;deploy&#8221; user.</li>
<li>You can specify an alternate SSH port for both your gateway <em>and</em> your deployment servers. E.g. setting <code>ssh_options[:port] = 11111</code> will make Capistrano SSH to your gateway server with on port 11111. For your actual application (and web and database) servers, you can specify the SSH port like so:
<pre><code class="ruby">set :gateway, 'deploy@deploy.example.com'
role :app, '192.168.1.113:22222'
role :web, '192.168.1.113:22222'
role :db,  '192.168.1.113:22222', :primary => true</code></pre>
</li>
<li>If you&#8217;re using public key authentication, you should put the public keys of your users (those who be deploying your app) on the gateway server <em>and</em> on the actual servers. I thought Capistrano would use the key of the &#8220;deploy&#8221; user but nope.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.codefront.net/2008/05/15/deploying-with-capistrano-via-a-gateway/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Living on the edge (of Rails) #19 &#8211; change_table for migrations and more</title>
		<link>http://blog.codefront.net/2008/05/04/living-on-the-edge-of-rails-19-change_table-for-migrations-and-more/</link>
		<comments>http://blog.codefront.net/2008/05/04/living-on-the-edge-of-rails-19-change_table-for-migrations-and-more/#comments</comments>
		<pubDate>Sun, 04 May 2008 12:18:54 +0000</pubDate>
		<dc:creator>Chu Yeow</dc:creator>
				<category><![CDATA[Edge Rails]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://blog.codefront.net/?p=1105</guid>
		<description><![CDATA[This week’s report covers changes from 29 April 2008 to 4th May 2008 (the day the corresponding Rails Envy podcast was recorded).
change_table for ActiveRecord migrations
Thanks to Jeff Dean, who also blogged about the new change_table feature in ActiveRecord migrations, you can now change a table with a block like so:
change_table :videos do &#124;t&#124;
  t.add_timestamps
 [...]]]></description>
			<content:encoded><![CDATA[<p>This week’s report covers changes from 29 April 2008 to 4th May 2008 (the day the corresponding <a href="http://railsenvy.com/podcast/">Rails Envy podcast</a> was recorded).</p>
<h3>change_table for ActiveRecord migrations</h3>
<p>Thanks to <a href="http://zilkey.com/">Jeff Dean</a>, who also <a href="http://zilkey.com/2008/4/29/new-rails-core-feature-proposal-super-sexy-migrations">blogged about the new change_table feature in ActiveRecord migrations</a>, you can now change a table with a block like so:</p>
<pre><code class="ruby">change_table :videos do |t|
  t.add_timestamps
  t.add_belongs_to :goat
  t.add_string :name, :email, :limit =&gt; 20
  t.remove_column :name, :email # takes multiple arguments
  t.rename :new_name
  t.string :new_string_column # executes against the renamed table name
end</code></pre>
<p>Some key things to note:</p>
<ul>
<li><code>add_XXX</code> would add a new column for you, e.g. <code>add_string</code> would add a new string field.</li>
<li>Of course, add_timestamps would add the magic <code>created_at</code> and <code>updated_at</code> datetime fields.</li>
<li><code>remove_column</code> now takes multiple arguments.</li>
<li><code>rename</code> would rename the table.</li>
</ul>
<p>Very nice, DRY enhancement, props to <a href="http://zilkey.com/">Jeff Dean</a> once again.</p>
<p>Related changeset: <a href="http://github.com/rails/rails/commit/96980bd561d79824b6cb6efbcbecdcbf8785d452">http://github.com/rails/rails/commit/96980bd561d79824b6cb6efbcbecdcbf8785d452</a></p>
<h3>ActiveRecord::Base.create takes a block like ActiveRecord::Base.new</h3>
<p>Yup now you can also <code>create</code> ActiveRecord objects with a block argument just like you could for <code>ActiveRecord::Base.new</code>:</p>
<pre><code class="ruby">@person = Person.create(params[:person]) do |p|
  p.name = 'Konata Izumi'
  p.age = 17
end</code></pre>
<p>Credit goes to <a href="http://www.workingwithrails.com/person/11022-adam-meehan">Adam Meehan</a> for this patch.</p>
<p>Related changeset: <a href="http://github.com/rails/rails/commit/dd120ede53eaf71dee76894998a81626b7a689fc">http://github.com/rails/rails/commit/dd120ede53eaf71dee76894998a81626b7a689fc</a></p>
<h3>Bugfix: change_column should be able to use :null => true on a field that<br />
formerly had false</h3>
<p>You can now use <code>change_column</code> in your migrations to alter a column as nullable if it was previously <code>NOT NULL</code>.</p>
<p>This bugfix is courtesy of Nate Wiger.</p>
<p>Related changeset: <a href="http://github.com/rails/rails/commit/10ef65a3b054270ed3d458ec8eb7c2b9a3e638f7">http://github.com/rails/rails/commit/10ef65a3b054270ed3d458ec8eb7c2b9a3e638f7</a></p>
<p>As always, let me know of any suggestions or how I can improve the Living on the Edge (of Rails) series.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codefront.net/2008/05/04/living-on-the-edge-of-rails-19-change_table-for-migrations-and-more/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Living on the Edge (of Rails) in French</title>
		<link>http://blog.codefront.net/2008/05/01/living-on-the-edge-of-rails-in-french/</link>
		<comments>http://blog.codefront.net/2008/05/01/living-on-the-edge-of-rails-in-french/#comments</comments>
		<pubDate>Wed, 30 Apr 2008 16:07:34 +0000</pubDate>
		<dc:creator>Chu Yeow</dc:creator>
				<category><![CDATA[Edge Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://blog.codefront.net/?p=1103</guid>
		<description><![CDATA[It looks like Cyril Mougel has translated my 2 latest posts to French: LotE #17 and #18. Thanks Cyril!
]]></description>
			<content:encoded><![CDATA[<p>It looks like <a href="http://blog.shingara.fr/">Cyril Mougel</a> has translated my 2 latest posts to French: <a href="http://blog.shingara.fr/articles/2008/04/24/vivre-avec-rails-edge-17">LotE #17</a> and <a href="http://blog.shingara.fr/articles/2008/04/29/vivre-avec-rails-edge-18">#18</a>. Thanks Cyril!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codefront.net/2008/05/01/living-on-the-edge-of-rails-in-french/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Living on the edge (of Rails) #18</title>
		<link>http://blog.codefront.net/2008/04/27/living-on-the-edge-of-rails-18/</link>
		<comments>http://blog.codefront.net/2008/04/27/living-on-the-edge-of-rails-18/#comments</comments>
		<pubDate>Sun, 27 Apr 2008 11:18:36 +0000</pubDate>
		<dc:creator>Chu Yeow</dc:creator>
				<category><![CDATA[Edge Rails]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://blog.codefront.net/?p=1102</guid>
		<description><![CDATA[This week’s report covers changes from 21 Apr 2008 to 27 Apr 2008 (the day the corresponding Rails Envy podcast was recorded).
Not much interesting to report this week &#8211; there were mostly a bunch of bugfixes and Ruby 1.8.7-compatibility commits.
Introduce ActiveResource::Base.timeout and rescuing from Timeout::Error in ActiveResource::Connection
These are 2 changes that I&#8217;d talked about earlier [...]]]></description>
			<content:encoded><![CDATA[<p>This week’s report covers changes from 21 Apr 2008 to 27 Apr 2008 (the day the corresponding <a href="http://railsenvy.com/podcast/">Rails Envy podcast</a> was recorded).</p>
<p>Not much interesting to report this week &#8211; there were mostly a bunch of bugfixes and Ruby 1.8.7-compatibility <a href="http://github.com/rails/rails/commits/master">commits</a>.</p>
<h3>Introduce ActiveResource::Base.timeout and rescuing from Timeout::Error in ActiveResource::Connection</h3>
<p>These are <a href="http://github.com/rails/rails/commit/105910429d5873dce677ef32eef5f705e0625d86">2</a> <a href="http://github.com/rails/rails/commit/cf32baf915442ffe153ec0e4d8148f147776c30a">changes</a> that I&#8217;d <a href="http://blog.codefront.net/2008/04/22/new-in-rails-activeresource-timeouts-and-why-it-matters/">talked about</a> earlier this week so I won&#8217;t repeat myself &#8211; take a read through <a href="http://blog.codefront.net/2008/04/22/new-in-rails-activeresource-timeouts-and-why-it-matters/">ActiveResource timeouts and why it matters</a>.</p>
<h3>Smart integer datatype for the MySQL adapter in migrations</h3>
<p>The MySQL adapter in Rails now maps the <code>integer</code> column type in your migrations to either smallint, int, or bigint depending on the :limit option.</p>
<p>This means that a migration like this:</p>
<pre><code class="ruby">def self.up
  create_table :searches do |t|
    t.integer :foo, :limit => 2
  end</code></pre>
<p>will create your <code>foo</code> column as a <code>smallint(2)</code> MySQL datatype (instead of <code>int(2)</code> before). (More information <a href="http://dev.mysql.com/doc/refman/5.0/en/numeric-types.html">MySQL numeric datatypes</a>.)</p>
<p>Credit goes to DHH for this patch.</p>
<p>Related changeset: <a href="http://github.com/rails/rails/commit/a37546517dad9f6d9a7de6e1dba4d960909d71e8">http://github.com/rails/rails/commit/a37546517dad9f6d9a7de6e1dba4d960909d71e8</a></p>
<p>As always, let me know of any suggestions or how I can improve the Living on the Edge (of Rails) series.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codefront.net/2008/04/27/living-on-the-edge-of-rails-18/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>New in Rails: ActiveResource timeouts and why it matters</title>
		<link>http://blog.codefront.net/2008/04/22/new-in-rails-activeresource-timeouts-and-why-it-matters/</link>
		<comments>http://blog.codefront.net/2008/04/22/new-in-rails-activeresource-timeouts-and-why-it-matters/#comments</comments>
		<pubDate>Tue, 22 Apr 2008 14:25:57 +0000</pubDate>
		<dc:creator>Chu Yeow</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Web development]]></category>

		<guid isPermaLink="false">http://blog.codefront.net/?p=1100</guid>
		<description><![CDATA[If you&#8217;ve ever used ActiveResource or for that matter, coded anything that involves interacting with a remote API, you&#8217;ve probably had the misfortune of having that API go down or become unresponsive. The experienced old geezers would already have forseen the problem and set a timeout on those API calls. For the rest of us, [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;ve ever used ActiveResource or for that matter, coded anything that involves interacting with a remote API, you&#8217;ve probably had the misfortune of having that API go down or become unresponsive. The experienced old geezers would already have forseen the problem and set a timeout on those API calls. For the rest of us, it&#8217;s a good time to get acquainted with the idea of <a href="http://en.wikipedia.org/wiki/Fail-fast">fail-fast</a> and how <em>no response is better than a slow response</em>.</p>
<p>So what happens when the API you&#8217;re accessing via ActiveResource or <code>Net::HTTP</code> (or whatever, really, so long as there&#8217;s a network socket involved!) becomes unresponsive?</p>
<h3>Unfettered outbound remote connections can kill your server</h3>
<p>ActiveResource (or <code>Net::HTTP</code> or whatever you&#8217;re using) would block while waiting for the API to return. What did we learn about blocking IO in Operating Systems 101? That your process or thread gets stuck waiting for a response that&#8217;s what. So now your Mongrel/Thin/Ebb/X web server process basically stuck waiting for a response from an API that might return a response in 30 seconds, or maybe it&#8217;ll never return at all. It won&#8217;t be long before all your web server processes get blocked and its time to &#8220;kill dash nine&#8221; (<code>kill -9</code>) some processes and bring out the 500 error page. Yes, your server has been incapacitated and your website is now basically offline.</p>
<div class="img"><img src="http://blog.codefront.net/wp-content/uploads/2008/04/im-in-ur-serverz.gif" alt="im in ur serverz making thingz better" /></div>
<p><br style="clear:both;" /></p>
<h3>Timeouts and you</h3>
<p>If you&#8217;re using Net::HTTP you can easily safeguard yourself against errors like this by setting a timeout on the socket connection. Like so:</p>
<pre><code class="ruby">def fetch_something_from_some_api(uri)
  http = Net::HTTP.new(uri.host, uri.port)
  http.read_timeout = timeout

  response = http.start { http.request(Net::HTTP::Get.new("#{uri.path}?#{uri.query}")) }
  response.is_a?(Net::HTTPSuccess) ? do_something_with(response.body) : nil
rescue Timeout::Error
  logger.warn("Timeout accessing #{uri}: #{$!}")
  nil
rescue
  logger.warn("Error accessing #{uri}: #{$!}")
  nil
end</code></pre>
<p>Take note that you really do need to explicitly rescue from the <code>Timeout::Error</code> (or <code>Interrupt</code>) since it&#8217;s a child of the <code>Interrupt</code> class and not a <code>StandardError</code>.</p>
<p>Any good client library should also allow you to specify a timeout on the socket connection so read the API documentation.</p>
<h3>So what&#8217;s this about ActiveResource?</h3>
<p>So back to ActiveResource: Michael Koziarski was kind enough to commit my 2 patches (<a href="http://github.com/rails/rails/commit/105910429d5873dce677ef32eef5f705e0625d86">this</a> and <a href="http://github.com/rails/rails/commit/cf32baf915442ffe153ec0e4d8148f147776c30a">this</a>) to ActiveResource so now on <a href="http://github.com/rails/rails/tree/master">edge Rails</a>, you can do this:</p>
<pre><code class="ruby">class Person &lt; ActiveResource::Base
  self.site = 'http://api.people.com:3000/'
  self.timeout = 5
end</code></pre>
<p>This sets the timeout to 5 seconds on the underlying <code>Net::HTTP</code> instance that ActiveResource uses. The default timeout (to be exact, the <code>read_timeout</code>) for <code>Net::HTTP</code> is <strong>60 seconds</strong> on most Ruby implementations (that includes MRI). That&#8217;s far too long if your ActiveResource call is in a public-facing controller!</p>
<p>If you are using ActiveResource anywhere and haven&#8217;t safeguarded your application with a timeout, I think it&#8217;s a good idea to fix it by using edge Rails or at least applying the <a href="http://github.com/rails/rails/commit/105910429d5873dce677ef32eef5f705e0625d86">patch</a>!</p>
<p>The <a href="http://github.com/rails/rails/commit/cf32baf915442ffe153ec0e4d8148f147776c30a">2nd ActiveResource patch</a> introduces the <code>ActiveResource::TimeoutError</code> exception that you should rescue from whenever you make an ActiveResource call. When this happens, it&#8217;s up to your application to decide what to do (like show a placating we&#8217;re sorry message). At least your application is still able to do something!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codefront.net/2008/04/22/new-in-rails-activeresource-timeouts-and-why-it-matters/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Living on the edge (of Rails) #17</title>
		<link>http://blog.codefront.net/2008/04/20/living-on-the-edge-of-rails-17/</link>
		<comments>http://blog.codefront.net/2008/04/20/living-on-the-edge-of-rails-17/#comments</comments>
		<pubDate>Sun, 20 Apr 2008 11:21:22 +0000</pubDate>
		<dc:creator>Chu Yeow</dc:creator>
				<category><![CDATA[Edge Rails]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://blog.codefront.net/?p=1099</guid>
		<description><![CDATA[Not much going on this week on edge Rails. It does seem however that we do have a new Rails core member, Joshua Peek. Also, the new Rails&#8217; bug tracker hosted on Lighthouse is ready for use, so be sure to submit your patches and bug reports there.
This week’s report covers changes from 14 Apr [...]]]></description>
			<content:encoded><![CDATA[<p>Not much going on this week on edge Rails. It does seem however that we do have a new Rails core member, <a href="http://joshpeek.com/">Joshua Peek</a>. Also, the new <a href="http://rails.lighthouseapp.com/">Rails&#8217; bug tracker</a> hosted on Lighthouse is ready for use, so be sure to submit your patches and bug reports there.</p>
<p>This week’s report covers changes from 14 Apr 2008 to 20 Apr 2008 (the day the corresponding <a href="http://railsenvy.com/podcast/">Rails Envy podcast</a> was recorded).</p>
<h3>Conditional caches_page</h3>
<p>The <code>caches_page</code> now takes an <code>:if</code> option for specifying when a page can actually be cached via a Proc. You can now do this, for example:</p>
<pre><code class="ruby">caches_page :index, :if =&gt; Proc.new { |c| !c.request.format.json? }</code></pre>
<p>That will only cache your index page if the requested format is not JSON.</p>
<p>Credit goes to <a href="http://deaddeadgood.com/">Paul Horsfall</a> for this enhancement.</p>
<p>Related changeset: <a href="http://github.com/rails/rails/commit/14a40804a29a57ad05ca6bffbe1e5334089593a9">http://github.com/rails/rails/commit/14a40804a29a57ad05ca6bffbe1e5334089593a9</a></p>
<h3>New ActionView::TestCase for testing view helpers</h3>
<p>Remember how you can now use <a href="http://blog.codefront.net/2007/12/27/dry-in-your-functional-and-actionmailer-tests-rails-20-a-feature-a-day-7/">specialized TestCase classes for testing controllers and ActionMailer classes</a>? Now you can do the same with your Rails view helpers with the new ActionView::TestCase class.</p>
<p>Here&#8217;s a quick example:</p>
<pre><code class="ruby">module PeopleHelper
  def title(text)
    content_tag(:h1, text)
  end

  def homepage_path
    people_path
  end
end

class PeopleHelperTest &lt; ActionView::TestCase
def setup
  ActionController::Routing::Routes.draw do |map|
    map.people 'people', :controller =&gt; 'people', :action =&gt; 'index'
    map.connect ':controller/:action/:id'
  end
end

def test_title
  assert_equal "&lt;h1&gt;Ruby on Rails&lt;/h1&gt;", title("Ruby on Rails")
end

def test_homepage_path
  assert_equal "/people", homepage_path
end</code></pre>
<p>Credit goes to Josh Peek for this sweet little enhancement.</p>
<h3>ActiveSupport::Cache&#8217;s mem_cache_store accepts options</h3>
<p>Even though Memcache-client was added to ActiveSupport recently, it didn&#8217;t allow you to specify any configuration options beyond just the IP of the memcached server. Now you can pass along more configuration options like so:</p>
<pre><code class="ruby">config.action_controller.fragment_cache_store = :mem_cache_store, 'localhost', { :compression =&gt; true, :debug =&gt; true, :namespace =&gt; 'foo' }</code></pre>
<p>This patch is courtesy of <a href="http://blog.innerewut.de/">Jonathan Weiss</a>.</p>
<p>Related changeset: <a href="http://github.com/rails/rails/commit/9e1d506a8cfedef2fdd605e4cbf4bf53651ad214">http://github.com/rails/rails/commit/9e1d506a8cfedef2fdd605e4cbf4bf53651ad214</a></p>
<p>As always, let me know of any suggestions or how I can improve the Living on the Edge (of Rails) series.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codefront.net/2008/04/20/living-on-the-edge-of-rails-17/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Living on the edge (of Rails) #16 &#8211; Github edition</title>
		<link>http://blog.codefront.net/2008/04/13/living-on-the-edge-of-rails-16-github-edition/</link>
		<comments>http://blog.codefront.net/2008/04/13/living-on-the-edge-of-rails-16-github-edition/#comments</comments>
		<pubDate>Sun, 13 Apr 2008 08:09:43 +0000</pubDate>
		<dc:creator>Chu Yeow</dc:creator>
				<category><![CDATA[Edge Rails]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://blog.codefront.net/?p=1097</guid>
		<description><![CDATA[A slight change this week since Rails has moved to Git &#8211; all changesets are now referenced to Github.
This week’s report covers changes from 7 Apr 2008 to 13 Apr 2008 (the day the corresponding Rails Envy podcast was recorded).
A helpers proxy method for accessing helper methods from outside of views
A helpers method has been [...]]]></description>
			<content:encoded><![CDATA[<p>A slight change this week since <a href="http://weblog.rubyonrails.org/2008/4/11/rails-premieres-on-github">Rails has moved to Git</a> &#8211; all changesets are now referenced to <a href="http://github.com/rails/rails/tree/master">Github</a>.</p>
<p>This week’s report covers changes from 7 Apr 2008 to 13 Apr 2008 (the day the corresponding <a href="http://railsenvy.com/podcast/">Rails Envy podcast</a> was recorded).</p>
<h3>A helpers proxy method for accessing helper methods from outside of views</h3>
<p>A <code>helpers</code> method has been introduced to ActionController &#8211; you can now access your helpers like so:</p>
<pre><code class="ruby">ApplicationController.helpers.simple_format(text)</code></pre>
<p>Credit goes to 19 year old <a href="http://joshpeek.com/">Josh Peek</a>, one of the more prolific Rails contributors (and most likely to join Pratik in Rails Core imo).</p>
<p>Related changeset: <a href="http://github.com/rails/rails/commit/917423d664038d6791738a73ad1446437dbb71df">http://github.com/rails/rails/commit/917423d664038d6791738a73ad1446437dbb71df</a></p>
<h3>json_escape for escaping HTML entities in JSON strings</h3>
<p>A <code>json_escape</code> (aliased as <code>j</code>, similar to how <code>html_escape</code> is aliased as <code>h</code>) has been introduced by Rick Olson for escaping HTML entities in JSON strings. This is useful if you find yourself emitting JSON strings in HTML pages (e.g. for documenting a JSON API):</p>
<pre><code class="ruby">json_escape("is a &gt; 0 &amp; a &lt; 10?")
# => is a \u003E 0 \u0026 a \u003C 10?</code></pre>
<p>Of course, since <code>json_escape</code> is aliased as <code>j</code>, you can do this in your ERB templates:</p>
<pre><code class="ruby"><%=j @person.to_json %></code></pre>
<p>Related changeset: <a href="http://github.com/rails/rails/commit/0ff7a2d89fc95dcb0a32ed92aab7156b0778a7ea">http://github.com/rails/rails/commit/0ff7a2d89fc95dcb0a32ed92aab7156b0778a7ea</a></p>
<h3>Automatically parse posted JSON content for Mime::JSON requests</h3>
<p>Rails will now accept POSTed JSON content! For example, you can now send a POST to &#8220;/posts&#8221; of your Post resource like this:</p>
<pre><code>POST /posts
{"post": {"title": "Breaking News"}}</code></pre>
<p>And your <code>create</code> action will automatically parse the POSTed JSON into the request <code>params</code> so that this code below just works:</p>
<pre><code class="ruby">def create
  @post = Post.create params[:post]
end</code></pre>
<p>Credit goes to Rick Olson.</p>
<p>Related changeset: <a href="http://github.com/rails/rails/commit/4d594cffcfc93b37fad4e423ec8593299e50133c">http://github.com/rails/rails/commit/4d594cffcfc93b37fad4e423ec8593299e50133c</a></p>
<h3>schema_migrations table replaces the schema_info table, allowing for interleaved migrations</h3>
<p>A new schema_migrations table for storing which migrations have been run has been introduced, and this replaces the existing schema_info table (which simply keeps track of the last applied schema version). This change makes it possible to add migrations (for example, after you&#8217;ve merged from someone&#8217;s branch) &#8211; when you migrate your database via rake db:migrate, those never-applied &#8220;interleaved&#8221; migrations will be run. Similarly, when migrating down schema versions, never-applied &#8220;interleaved&#8221; will be skipped.</p>
<p>See <a href="http://dev.rubyonrails.org/ticket/11493">http://dev.rubyonrails.org/ticket/11493</a> for more information.</p>
<p>This useful patch is the brainchild of <a href="http://bunster.org/">Jordi Bunster</a> (<a href="http://www.workingwithrails.com/person/12130-jordi-bunster">WWR profile</a>). I&#8217;m sure many Rails developers who branch extensively will thank Jordi for this excellent patch!</p>
<p>Related changeset: <a href="http://github.com/rails/rails/commit/8a5a9dcbf64843f064b6e8a0b9c6eea8f0b8536e">http://github.com/rails/rails/commit/8a5a9dcbf64843f064b6e8a0b9c6eea8f0b8536e</a></p>
<h3>gems:unpack:dependencies Rake task</h3>
<p>Remember how you can now run the <code>gems:unpack</code> Rake task to unpack a gem into your <code>vendor/gems/</code> directory (this was <a href="http://blog.codefront.net/2008/04/05/living-on-the-edge-of-rails-14-the-extreme-edition-extremely-late/">mentioned in an earlier Living on the Edge</a>)?</p>
<p>David Dollar (<a href="http://github.com/ddollar">Github profile</a>) has firmed up that patch quite a bit by adding the <code>gems:unpack:dependencies</code> Rake task that unpacks the dependencies of the gems as well. So running:</p>
<pre><code>gems:unpack:dependencies GEM=activecouch</code></pre>
<p>would unpack the full Rubygem dependency tree of gems that the <a href="http://code.google.com/p/activecouch/">activecouch</a> gem depends upon.</p>
<p>Related changeset: <a href="http://github.com/rails/rails/commit/4364c361b599f99bc2345ce4eb2d145b07ed8a0f">http://github.com/rails/rails/commit/4364c361b599f99bc2345ce4eb2d145b07ed8a0f</a></p>
<p>As always, let me know of any suggestions or how I can improve the Living on the Edge (of Rails) series! Now go out there and start <a href="http://github.com/rails/rails/tree/master">forking Rails</a>!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codefront.net/2008/04/13/living-on-the-edge-of-rails-16-github-edition/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Living on the edge (of Rails) #15 &#8211; the early edition</title>
		<link>http://blog.codefront.net/2008/04/06/living-on-the-edge-of-rails-15-the-early-edition/</link>
		<comments>http://blog.codefront.net/2008/04/06/living-on-the-edge-of-rails-15-the-early-edition/#comments</comments>
		<pubDate>Sun, 06 Apr 2008 07:57:01 +0000</pubDate>
		<dc:creator>Chu Yeow</dc:creator>
				<category><![CDATA[Edge Rails]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://blog.codefront.net/?p=1096</guid>
		<description><![CDATA[I&#8217;m gonna post up the Living on the Edge a little earlier this week because I&#8217;ve found I just can&#8217;t keep up (when things get busy) with 2 separate sets of notes for the Rails Envy podcast and another for my own blog posts.
From this week onwards, I&#8217;ll be following Pratik&#8217;s suggestion to post about [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m gonna post up the Living on the Edge a little earlier this week because I&#8217;ve found I just can&#8217;t keep up (when things get busy) with 2 separate sets of notes for the <a href="http://railsenvy.com/podcast/">Rails Envy podcast</a> and another for my own blog posts.</p>
<p>From this week onwards, I&#8217;ll be following <a href="http://m.onkey.org">Pratik</a>&#8217;s suggestion to post about changes as they happen instead of after an entire week so expect a slight change in the format of Living on the edge for next week!</p>
<p>This week’s report covers changes from 31 Mar 2008 to 6 Apr 2008 (the day the corresponding <a href="http://railsenvy.com/podcast/">Rails Envy podcast</a> was recorded).</p>
<h3>Rails.env, Rails.logger, Rails.cache, Rails.root</h3>
<p>This has been a long time coming: You can now use <code>Rails.env</code> instead of <code>RAILS_ENV</code>, <code>Rails.root</code> instead of <code>RAILS_ROOT</code>, <code>Rails.logger</code> instead of <code>RAILS_DEFAULT_LOGGER</code>, and <code>Rails.cache</code> instead of <code>RAILS_CACHE</code>. Not having to use constants is nice because it always felt a bit dirty to have so many hard-coded constants in the Rails namespace.</p>
<p>Credit goes to <a href="http://m.onkey.org/">Pratik Naik</a>, the newest Rails core team member for this cleanup.</p>
<p>Related changeset: <a href="http://dev.rubyonrails.org/changeset/9180">http://dev.rubyonrails.org/changeset/9180</a></p>
<h3>Render :partial now works with a collection of heterogeneous elements</h3>
<p>You can now use <code>render :partial</code> to render a collection of different elements and Rails will figure out which partial template to use. For example:</p>
<pre><code class="ruby">render :partial => [ monkey, donkey, dramatic_chipmunk ]</code></pre>
<p>will render the monkey with the &#8216;monkeys/_monkey.html.erb&#8217; partial, donkey with the &#8216;donkeys/_donkey.html.erb&#8217; partial, and last but definitely not lest, dramatic_gopher with the &#8216;dramatic_chipmunks/_dramatic_chipmunk.html.erb&#8217; partial</p>
<p>This is especially useful if when using <acronym title="Single Table Inheritance">STI</acronym>, where your ActiveRecord model would return objects of different types. The collection <code>[ monkey, donkey, dramatic_chipmunk ]</code> could very well be something returned from your <code>Animal</code> model that has subclasses of <code>Monkey</code>, <code>Donkey</code> and <code>DramaticChipmunk</code> via STI.</p>
<p>Credit: <a href="http://www.continuousthinking.com/">Zach Dennis</a> of <a href="http://www.continuousthinking.com/tags/arext">ar-extensions</a> fame.</p>
<p>Related changeset: <a href="http://dev.rubyonrails.org/changeset/9177">http://dev.rubyonrails.org/changeset/9177</a></p>
<h3>ActiveModel work revived</h3>
<p>It seems like work on ActiveModel (think unified ActiveRecord and ActiveResource behaviors) has been revived, if the latest commits (<a href="http://dev.rubyonrails.org/changeset/9171">http://dev.rubyonrails.org/changeset/9171</a> and <a href="http://dev.rubyonrails.org/changeset/9173">http://dev.rubyonrails.org/changeset/9173</a>) by David (DHH) is anything to go by.</p>
<h3>Bugfix: Assigning an invalid has_one association now causes #save to fail on parent</h3>
<p>You could do this before:</p>
<pre><code class="ruby">firm = Firm.find(:first)
firm.account = Account.new # Associate INVALID account
firm.save # This doesn't fail</code></pre>
<p>Now that&#8217;s fixed thanks to <a href="http://m.onkey.org/">Pratik Naik</a>.</p>
<p>Related changeset: <a href="http://dev.rubyonrails.org/changeset/9232">http://dev.rubyonrails.org/changeset/9232</a></p>
<p>As usual, any feedback is respectfully appreciated!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codefront.net/2008/04/06/living-on-the-edge-of-rails-15-the-early-edition/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Living on the edge (of Rails) #14 &#8211; the extreme edition. Extremely late.</title>
		<link>http://blog.codefront.net/2008/04/05/living-on-the-edge-of-rails-14-the-extreme-edition-extremely-late/</link>
		<comments>http://blog.codefront.net/2008/04/05/living-on-the-edge-of-rails-14-the-extreme-edition-extremely-late/#comments</comments>
		<pubDate>Fri, 04 Apr 2008 16:04:06 +0000</pubDate>
		<dc:creator>Chu Yeow</dc:creator>
				<category><![CDATA[Edge Rails]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://blog.codefront.net/2008/04/05/living-on-the-edge-of-rails-14-the-extreme-edition-extremely-late/</guid>
		<description><![CDATA[This week’s report covers changes from 24 Mar 2008 to 30 Mar 2008 (the day the corresponding Rails Envy podcast was recorded).
There&#8217;re lots of big exciting changes this week on edge. Smells like 2.1 soon!
has_finder gem merged into Rails
Ryan Daigle has the scoop on the new has_finder-like functionality in Rails so head on over (I [...]]]></description>
			<content:encoded><![CDATA[<p>This week’s report covers changes from 24 Mar 2008 to 30 Mar 2008 (the day the corresponding <a href="http://railsenvy.com/podcast/">Rails Envy podcast</a> was recorded).</p>
<p>There&#8217;re lots of big exciting changes this week on edge. Smells like 2.1 soon!</p>
<h3>has_finder gem merged into Rails</h3>
<p>Ryan Daigle has <a href="http://ryandaigle.com/articles/2008/3/24/what-s-new-in-edge-rails-has-finder-functionality">the scoop on the new has_finder-like functionality in Rails</a> so head on over (I won&#8217;t repeat it here in the interests of <acronym title="Don't Repeat Yourself">DRY</acronym>).</p>
<p>Credit goes to <a href="http://pivots.pivotallabs.com/users/nick/blog/articles/284-hasfinder-it-s-now-easier-than-ever-to-create-complex-re-usable-sql-queries">Nick Kallen</a> for coming up with the has_finder gem.</p>
<p>Related changeset: <a href="http://dev.rubyonrails.org/changeset/9084">http://dev.rubyonrails.org/changeset/9084</a></p>
<h3>ActiveRecord: Unsaved attribute changes are now tracked</h3>
<p>You can now ask an ActiveRecord model whether its attributes have been changed (and is unsaved) using the <code>{attr_name}_changed?</code> (magic) method. The <code>{attr_name}_was</code> method will return the original value of the attribute, and the <code>{attr_name}_change</code> method will return an array with 2 members, the 1st being the original value, the 2nd being the changed (and unsaved) value.</p>
<pre><code class="ruby"># Change person's name.
person.name = 'Jason Seifer'
person.changed?       # => true
person.name_changed?  # => true
person.name_was       # => 'jseifer'
person.name_change    # => ['jseifer', 'Jason Seifer']
person.name = 'Ceiling Cat'
person.name_change    # => ['jseifer', 'Ceiling Cat']</code></pre>
<p>Credit goes to Rails core team member Jeremy Kemper (bitsweat) for this patch (which originated from Jeremy&#8217;s very own <a href="http://code.bitsweat.net/svn/dirty">Dirty plugin</a>).</p>
<p>Related changeset: <a href="http://dev.rubyonrails.org/changeset/9127">http://dev.rubyonrails.org/changeset/9127</a></p>
<h3>ActiveRecord#Base.all/first/last</h3>
<p>Now you can do:</p>
<pre><code class="ruby">Post.all.each { |post| # something }
Post.first
Post.last</code></pre>
<p>Kinda like how some other ORMs do (like DataMapper).</p>
<p>Credit: <a href="http://www.thechrisoshow.com/">thechrisoshow</a> and again, Nick Kallen for has_finder.</p>
<p>Related changeset: <a href="http://dev.rubyonrails.org/changeset/9085">http://dev.rubyonrails.org/changeset/9085</a></p>
<h3>Timestamped Migrations</h3>
<p>This is more useful than it sounds: migrations are now timestamped instead of using incremental numbers in your db/migrate folder. This eliminates the problem of migrations having the same version number when working on a multi-developer Rails app.</p>
<p>Two new Rake tasks, rake <code>db:migrate:up/down</code>, have been added to allow running of the <code>up</code> and <code>down</code> methods of individual migrations.</p>
<p>Credit goes to John Barnette, the guy who gave you <a href="http://ryandaigle.com/articles/2007/10/26/what-s-new-in-edge-rails-fixtures-just-got-a-whole-lot-easier">foxy fixtures</a>.</p>
<p>Related changeset:<a href=" http://dev.rubyonrails.org/changeset/9122"> http://dev.rubyonrails.org/changeset/9122</a></p>
<h3>New config.gem option for specifying which gems are required by the application + rake tasks for installing and freezing gems</h3>
<p>Specify which gems are required by your Rails app in your Rails <code>environment.rb</code>! &#8220;Vendor everything&#8221; supported right in Rails :). An example:</p>
<pre><code class="ruby">Rails::Initializer.run do |config|
  config.gems 'chronic'
  config.gems "hpricot", :version => '0.6', :source => "http://code.whytheluckystiff.net"
  config.gems "aws-s3", :lib => "aws/s3"
end</code></pre>
<p>There are also new Rake tasks:</p>
<pre><code class="ruby"># List required gems.
rake gems 

# Install all required gems:
rake gems:install 

# Unpack specified gem to vendor/gems/gem_name-x.x.x
rake gems:unpack GEM=chronic</code></pre>
<p>Credit goes to the prolific <a href="http://techno-weenie.net/">Rick Olson</a> for this gem of a patch.</p>
<p>Related changeset: <a href="http://dev.rubyonrails.org/changeset/9140">http://dev.rubyonrails.org/changeset/9140</a></p>
<h3>ActiveResource #clone</h3>
<p>You can now clone an existing resource:</p>
<pre><code class="ruby">gregg = Person.find(1)
borg = gregg.clone</code></pre>
<p>This doesn&#8217;t clone child ActiveResource members though, just the straight up attributes of resource.</p>
<p>Contribors: <a href="http://ryandaigle.com/">Ryan Daigle</a> and <a href="http://www.thechrisoshow.com/">thechrisoshow</a>.</p>
<p>Related changeset: <a href="http://dev.rubyonrails.org/changeset/9121">http://dev.rubyonrails.org/changeset/9121</a></p>
<h3>Big documentation patch</h3>
<p>A big doc patch consisting of all the efforts going on in the <a href="http://github.com/lifo/doc-rails/">doc-rails repository on Github</a> has been committed. Check out <a href="http://groups.google.com/group/rubyonrails-core/browse_thread/thread/92f822141df3c217/71e7460d41bdfd89">Pratik&#8217;s post</a> for more info on what doc-rails is. Though with Rails moving to Git soon, doc-rails may no longer be necessary!</p>
<p>Related changeset: <a href="http://dev.rubyonrails.org/changeset/9093">http://dev.rubyonrails.org/changeset/9093</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codefront.net/2008/04/05/living-on-the-edge-of-rails-14-the-extreme-edition-extremely-late/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
