<?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>jonathanjulian.com &#187; Ruby</title>
	<atom:link href="http://jonathanjulian.com/category/ruby/feed/" rel="self" type="application/rss+xml" />
	<link>http://jonathanjulian.com</link>
	<description>Ruby, Rails, JavaScript, software development</description>
	<lastBuildDate>Fri, 13 Jan 2012 21:03:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>My favorite parts of RubyNation 2011</title>
		<link>http://jonathanjulian.com/2011/04/my-favorite-parts-of-rubynation-2011/</link>
		<comments>http://jonathanjulian.com/2011/04/my-favorite-parts-of-rubynation-2011/#comments</comments>
		<pubDate>Mon, 04 Apr 2011 01:03:49 +0000</pubDate>
		<dc:creator>jonathan</dc:creator>
				<category><![CDATA[git]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://jonathanjulian.com/?p=294</guid>
		<description><![CDATA[RubyNation was held this past weekend in Reston VA, and it was a success for the fourth year in a row. For being a (relatively) small regional conference, we consistently get to see quality speakers and draw Rubyists from North Carolina all the way to Philadelphia (and much further, I&#8217;m sure). I&#8217;ve been every year [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://rubynation.org"><img alt="RubyNation 2011 badge" src="http://www.rubynation.org/images/conference/badges/2011/webBadgesConference.png" title="RubyNation 2011" class="alignright" width="180" height="135" /></a>
<a href="http://rubynation.org">RubyNation</a> was held this past weekend in Reston VA, and it was a success for the fourth year in a row. For being a (relatively) small regional conference, we consistently get to see quality speakers and draw Rubyists from North Carolina all the way to Philadelphia (and much further, I&#8217;m sure). I&#8217;ve been every year (it&#8217;s just a little over an hour from Baltimore), and I always have a great time. Here is what I thought were the best parts of RubyNation 2011.</p>

<h3>Hanging out with friends</h3>

<p>We always have a strong contingent of <a href="http://bmoreonrails.org">Bmore on Rails</a> folks at RubyNation. This weekend I twice received unsolicited praise that the Bmore on Rails group was &#8220;friendly and cohesive&#8221; and &#8220;one of the more fun local groups&#8221;. I&#8217;m paraphrasing, but it was awesome to hear that others see us this way. It&#8217;s true!</p>

<h3>Making new friends</h3>

<p>I can&#8217;t even count how many colleagues I&#8217;ve met at previous RubyNations! I don&#8217;t feel like I met <em>too</em> many new folks this year, but it&#8217;s still a big part of any local conference to me. If you met me (or even if you didn&#8217;t), make sure to keep in touch on twitter!</p>

<h3>The Talks</h3>

<p>I was lucky, I had already seen three of the sessions at Bmore on Rails in the last few months (&#8220;Fat Models Aren&#8217;t Enough&#8221; by <a href="http://jumpstartlab.com">Jeff Casimir</a>, &#8220;Confident Code&#8221; by <a href="http://avdi.org">Avdi Grimm</a>, and &#8220;KnowSQL: Database Tricks to Make Your Life Easier&#8221; by <a href="http://www.ngauthier.com/">Nick Gauthier</a>). This made it easy for me to see a couple of new talks.</p>

<h3>&#8220;Git: It&#8217;s All About the Trees, Baby&#8221; by <a href="http://scottchacon.com/">Scott Chacon</a></h3>

<p>Scott obviously knows git inside and out. The details are complex, and I&#8217;m mystified about it on a regular basis, even though I&#8217;ve been using it for over 3 years. I love how Scott slows down to ask, &#8220;Does that make sense?&#8221; after every difficult concept. I took feverish notes and re-read them a few times &#8211; after some digestion, yes, Scott, now it does make sense. I think. <a href="https://github.s3.amazonaws.com/presentations/three_trees.pdf">slides</a></p>

<h3>&#8220;Make Awesome Command Line Applications in Ruby&#8221; by <a href="http://www.naildrivin5.com/">David Copeland</a></h3>

<p>For some reason, this topic speaks to me. Maybe it was all the shell scripts I wrote early in my career, or my love for the &#8220;UNIX way&#8221; of building large systems from many small tools. This was one of those talks that probably snuck under the radar, but those who were there know that they took away a ton of knowledge. I&#8217;m looking forward to David&#8217;s upcoming PragProg book on the subject! <a href="http://awesome-cli-ruby.heroku.com/">slides</a></p>

<h3>&#8220;Search-Friendly Web Development&#8221; by <a href="http://luigimontanez.com/">Luigi Montanez</a></h3>

<p>It must be tough to be the first session of day 2 of a conference (wait, <a href="/2010/06/proof-that-i-was-at-jsconf-2010-hangover-js/">it is</a>). I wonder how many people were scared off by the thought of this being an &#8220;SEO&#8221; talk? Well, it was. And it was excellent. To web developers, SEO doesn&#8217;t have to be much more than checking off a few boxes. Really &#8211; it&#8217;s not crazy difficult. Luigi laid out 
a great plan to help your site be more successful: by optimizing crawling, indexing and ranking. 
I&#8217;ve been forced to learn a ton about this subject while working on <a href="http://replyz.com">replyz.com</a> &#8211; we have a footprint of close to 10 million urls, so managing searchability and the sitemaps has been one of my jobs for close to a year. Great job, Luigi! <a href="http://www.slideshare.net/luigimontanez/searchfriendly-web-development-at-rubynation">slides</a></p>

<h3>&#8220;The JavaScript Renaissance&#8221; by <a href="http://voodootikigod.com/">Chris Williams</a></h3>

<p>Chris is a showman. Did he really hand out 200 pirate hats? When his speakers weren&#8217;t loud enough, did he really voice-over <a href="http://www.youtube.com/watch?v=O2rGTXHvPCQ">the Numb3rs episode where they explain IRC</a>? And did he really convince a room full of Rubyists that their favorite language has strong competition from other programming languages? Yep.</p>

<h3>&#8220;Must. Try. Harder.&#8221; by <a href="http://www.keavy.co.uk/">Keavy McMinn</a></h3>

<p>Every conference needs at least one inspirational talk. And this one fit the bill perfectly. Keavy&#8217;s even-paced delivery and detailed descriptions of the agonies of triathlon training provided a great analogy to our software development careers. The video of the harrowing descent left the room silent for a full minute and a half. Well done!</p>

<h3>Jeff Casimir setting up his gear to take headshots</h3>

<p>Jeff is the coolest. He gives a brief lightning talk imploring everyone to use their <em>face</em> as their avatar, not a cartoon or a logo. Then he invites everyone to step out into the lobby where he has set up a temporary studio &#8211; complete with a backdrop and two remote flashes. Fifty people stepped up and got their photo taken, and Jeff posted the results to flickr the next morning. <strong>The next morning.</strong> Seriously, this guy is awesome. <strong>By the way, are you looking for Ruby or Rails training? Check out <a href="http://jumpstartlab.com/">Jumpstart Lab</a>.</strong> <em>(Also, why are so many folks afraid to step in front of a camera? You know we all can see you right now, right?)</em>
<br/>
<a href="http://www.flickr.com/photos/jcasimir/sets/72157626415670430/"><img alt="headshots taken by Jeff Casimir at RubyNation 2011" src="/wp-content/uploads/2011/04/j3-headshots.png" class="alignleft" width="420" style="margin-bottom:15px"/></a></p>

<h3>&#8220;Your code is awesome. Your copy sucks.&#8221;</h3>

<p>I love lightning talks &#8211; you never know what you&#8217;re gonna get, and the investment is low (5 minutes). This year my favorite was about copy writing (that&#8217;s the stuff between the tags that the user sees). Andrea from <a href="http://www.corgibytes.com/">corgibytes</a> let the uber-techie, male-dominated audience know that the words you write matter. I play the role of copy writer for a few minutes (!) every week, and I appreciate raising awareness about this under-appreciated skill.</p>

<h3>The Hacking</h3>

<p>There was considerably less code hacking this year &#8211; but we still fit some in. <a href="http://paulbarry.com/">Paul Barry</a> wrote a <a href="https://github.com/pjb3/Conflagration">Ruby chat server</a> in the few minutes leading up to Nick Gauthier&#8217;s talk. And I told <a href="http://webandy.com/">Andy Atkinson</a> my idea for listing members on <a href="http://bmoreonrails.org">bmoreonrails.org</a>, and he ran with it and started the feature! (hopefully we&#8217;ll have members listed on the site this week)</p>

<h3>The Party</h3>

<p>Github sponsored the drinks, Living Social sponsored the food. And it was at a Westin. Do I need to say more? If you were there, I&#8217;d love to hear your thoughts on the mini-burgers (I thought they were the coolest things ever).</p>

<h3>My Conclusion</h3>

<p>It was another fun local conference. Congrats to Gray Herter and David Keener and David Bock, and <a href="http://www.rubynation.org/organizers">everyone else</a> who organizes RubyNation every year. Keep in mind that these were <em>my</em> favorite parts of RubyNation &#8211; yours will most likely be different. What did you enjoy most about the conference? What did I miss?</p>
]]></content:encoded>
			<wfw:commentRss>http://jonathanjulian.com/2011/04/my-favorite-parts-of-rubynation-2011/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Rails to_json or as_json?</title>
		<link>http://jonathanjulian.com/2010/04/rails-to_json-or-as_json/</link>
		<comments>http://jonathanjulian.com/2010/04/rails-to_json-or-as_json/#comments</comments>
		<pubDate>Sun, 04 Apr 2010 17:08:36 +0000</pubDate>
		<dc:creator>jonathan</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://jonathanjulian.com/?p=187</guid>
		<description><![CDATA[A really great modification was introduced in Rails 2.3.3 &#8211; and while everyone clamored about JSON encoding speeds and C vs Ruby implementations, the blogosphere overlooked the clean separation of responsibility that was introduced. In the &#8220;old days&#8221;, you&#8217;d override to_json in your model class to provide a JSON implementation of your model. Then in [...]]]></description>
			<content:encoded><![CDATA[<p>A really great modification was introduced in <a href="http://weblog.rubyonrails.org/2009/7/20/rails-2-3-3-touching-faster-json-bug-fixes">Rails 2.3.3</a> &#8211; and while everyone clamored about JSON <a href="http://www.ruby-forum.com/topic/200017">encoding speeds</a> and <a href="http://flori.github.com/json/">C vs Ruby implementations</a>, the blogosphere overlooked the clean separation of responsibility that was introduced.</p>

<p>In the &#8220;old days&#8221;, you&#8217;d override <code>to_json</code> in your model class to provide a JSON implementation of your model. Then in your controller, <code>render :json =&gt; @model</code> would work perfectly. And some folks would even redundantly code <code>render :json =&gt; @model.to_json</code>, and that would work too.</p>

<p><code>to_json</code> even had some great options for ActiveRecord objects! You could tell the method to only render certain attributes, or to include associations or method calls!</p>

<pre><code>render :json =&gt; 
  @user.to_json(:only =&gt; [:email], :include =&gt; [:addresses])
</code></pre>

<p>Life was good. But things start to fall apart when you want to do something a little out of the ordinary. Like return JSON with the model as part of a bigger structure.</p>

<pre><code>render :json =&gt; { :success =&gt; true, 
  :user =&gt; @user.to_json(:only =&gt; [:email]) }
</code></pre>

<p>Oops. <code>{\"user\":{\"email\":\"me@example.com\","success":true}</code>has the JSON characters <em>escaped</em>, which is not what we want. So what do we do? We hack around it:</p>

<pre><code>render :json =&gt; { :success =&gt; true, 
  :user =&gt; { :email =&gt; @user.email } }
</code></pre>

<p>But this doesn&#8217;t scale &#8211; we have to explicitly create the JSON <em>by hand</em> in the <em>controller</em>. What if we need 5 or more attributes? Yuck!</p>

<p>Enter <strong>ActiveSupport 2.3.3</strong>. Now the <em>creation</em> of the json is separate from the <em>rendering</em> of the json. <code>as_json</code> is used to create the structure of the JSON as a Hash, and the rendering of that hash into a JSON string is left up to <a href="http://as.rubyonrails.org/classes/ActiveSupport/JSON.html"><code>ActiveSupport::json.encode</code></a>. You should never use <code>to_json</code> to <em>create</em> a representation, only to <em>consume</em> the representation.</p>

<pre><code>def as_json(options={})
  { :email =&gt; self.email }
end
</code></pre>

<p>Anytime <code>to_json</code> is called on an object, <code>as_json</code> is invoked to create the data structure, and then that hash is encoded as a JSON string using <code>ActiveSupport::json.encode</code>. This happens for all types: Object, Numeric, Date, String, etc (see <a href="http://github.com/rails/rails/tree/2-3-stable/activesupport/lib/active_support/json">active_support/json</a>).</p>

<p>ActiveRecord objects behave the same way. There is a default <code>as_json</code> <a href="http://github.com/rails/rails/blob/2-3-stable/activerecord/lib/active_record/serializers/json_serializer.rb">implementation</a> that creates a Hash that includes all the model&#8217;s attributes. <strong>You should override <code>as_json</code> in your Model to create the JSON structure you want</strong>. <code>as_json</code>, just like the old <code>to_json</code>, takes an option hash where you can specify attributes and methods to include declaratively.</p>

<pre><code>def as_json(options={})
  super(:only =&gt; [:email, :avatar], :include =&gt;[:addresses])
end
</code></pre>

<p>Your controller code to display one model should always look like this:</p>

<pre><code>render :json =&gt; @user
</code></pre>

<p>And if you have to do anything <a href="http://namxam.tumblr.com/post/396486333/rails-as-json-vs-to-json">out of the ordinary</a>, call <code>as_json</code> passing your options.</p>

<pre><code>render :json =&gt; { :success =&gt; true, 
  :user =&gt; @user.as_json(:only =&gt; [:email]) }
</code></pre>

<p>The moral of the story is: <strong>In controllers, do not call <code>to_json</code> directly, allow <code>render</code> to do that for you. If you need to tweak the JSON output, override <code>as_json</code> in your model, or call <code>as_json</code> directly.</strong></p>

<p>Fix your code now to use <code>as_json</code> &#8211; it will be one less thing to worry about when you migrate to Rails 3.</p>

<p><em>This post was inspired by the investigation I went into while exploring the answer to <a href="http://stackoverflow.com/questions/2572284/override-to-json-in-rails-2-3-5/2574900">this question on Stack Overflow</a>.</em></p>

<p><em>Hey Brian Morearty &#8211; Rails was never Javaficated to begin with. So the answer is <a href="http://bmorearty.wordpress.com/2009/07/20/to_json-as_json/">yes</a>.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://jonathanjulian.com/2010/04/rails-to_json-or-as_json/feed/</wfw:commentRss>
		<slash:comments>26</slash:comments>
		</item>
		<item>
		<title>Introduction to delayed_job</title>
		<link>http://jonathanjulian.com/2009/11/introduction-to-delayed_job/</link>
		<comments>http://jonathanjulian.com/2009/11/introduction-to-delayed_job/#comments</comments>
		<pubDate>Wed, 11 Nov 2009 13:03:58 +0000</pubDate>
		<dc:creator>jonathan</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://jonathanjulian.com/?p=119</guid>
		<description><![CDATA[I gave this short presentation at the November bmore-on-rails meeting last night. Flip Sasser also presented an overview of Resque, and Michael Dotterer showed us a bit about background_job. We decided that delayed_job is an easy and solid way to get background tasks running in your Rails app, but if you are a massive site that [...]]]></description>
			<content:encoded><![CDATA[<p>I gave this short presentation at the <a href="http://www.meetup.com/bmore-on-rails/calendar/11620904/">November</a> <a href="http://www.meetup.com/bmore-on-rails/">bmore-on-rails</a> meeting last night. <a href="http://twitter.com/flipsasser">Flip Sasser</a> also presented an overview of <a href="http://github.com/blog/542-introducing-resque">Resque</a>, and <a href="http://www.workingwithrails.com/person/17379-michael-dotterer">Michael Dotterer</a> showed us a bit about <a href="http://codeforpeople.rubyforge.org/svn/bj/trunk/README">background_job</a>.</p>

<p>We decided that delayed_job is an easy and solid way to get background tasks running in your Rails app, but if you are a massive site that needs a heavy-duty and configurable solution, then Resque may be what you need. Resque&#8217;s complexity makes this a non-trivial decision! Start with delayed_job since it&#8217;s so quick to implement, and you can always choose another solution later.</p>

<div id="__ss_2467230" style="width: 425px; text-align: left;"><a style="font:14px Helvetica,Arial,Sans-serif;display:block;margin:12px 0 3px 0;text-decoration:underline;" title="Introduction To Delayed Job" href="http://www.slideshare.net/jonathanjulian/introduction-to-delayed-job">Introduction To Delayed Job</a><object style="margin:0px" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="355" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always" /><param name="src" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=introtodelayedjob-091110110012-phpapp01&amp;stripped_title=introduction-to-delayed-job" /><param name="allowfullscreen" value="true" /><embed style="margin:0px" type="application/x-shockwave-flash" width="425" height="355" src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=introtodelayedjob-091110110012-phpapp01&amp;stripped_title=introduction-to-delayed-job" allowscriptaccess="always" allowfullscreen="true"></embed></object>
<div style="font-size: 11px; font-family: tahoma,arial; height: 26px; padding-top: 2px;">View more <a style="text-decoration:underline;" href="http://www.slideshare.net/">documents</a> from <a style="text-decoration:underline;" href="http://www.slideshare.net/jonathanjulian">Jonathan Julian</a>.</div>
</div>

<p>Want to get delayed_job running in your app in 10 minutes? Follow the steps in <a href="http://railstips.org/2008/11/19/delayed-gratification-with-rails">Delayed Gratification with Rails</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://jonathanjulian.com/2009/11/introduction-to-delayed_job/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Wrapping a div around will_paginate page_entries_info</title>
		<link>http://jonathanjulian.com/2009/11/wrapping-a-div-around-will_paginate-page_entries_info/</link>
		<comments>http://jonathanjulian.com/2009/11/wrapping-a-div-around-will_paginate-page_entries_info/#comments</comments>
		<pubDate>Mon, 09 Nov 2009 20:19:26 +0000</pubDate>
		<dc:creator>jonathan</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://jonathanjulian.com/?p=116</guid>
		<description><![CDATA[The page_entries_info view helper looks great, but it is just plain text; I can&#8217;t add margin or padding or float it. Here&#8217;s a quick alias_method to wrap it up in a div with the class of your choice. Just drop that into an file in config/initializers, restart, and get styling!]]></description>
			<content:encoded><![CDATA[<p>The page_entries_info view helper looks great, but it is just plain text; I can&#8217;t add margin or padding or float it. Here&#8217;s a quick alias_method to wrap it up in a div with the class of your choice.</p>

<script src="http://gist.github.com/230245.js"></script>

<p>Just drop that into an file in config/initializers, restart, and get styling!</p>
]]></content:encoded>
			<wfw:commentRss>http://jonathanjulian.com/2009/11/wrapping-a-div-around-will_paginate-page_entries_info/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>I just entered RPCFN #2</title>
		<link>http://jonathanjulian.com/2009/10/i-just-entered-rpcfn-2/</link>
		<comments>http://jonathanjulian.com/2009/10/i-just-entered-rpcfn-2/#comments</comments>
		<pubDate>Thu, 08 Oct 2009 19:58:20 +0000</pubDate>
		<dc:creator>jonathan</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://jonathanjulian.com/?p=110</guid>
		<description><![CDATA[I don&#8217;t consider myself a Ruby newbie, but I was drawn to the Ruby Programming Challenge For Newbies #2 today. I&#8217;ll post and explain my solution when the contest is over! Thanks to Chris Strom for submitting the challenge!]]></description>
			<content:encoded><![CDATA[<p>I don&#8217;t consider myself a Ruby newbie, but I was drawn to the <a href="http://rubylearning.com/blog/2009/10/08/rpcfn-average-arrival-time-for-a-flight-2/">Ruby Programming Challenge For Newbies #2</a> today. I&#8217;ll post and explain my solution when the contest is over! Thanks to <a href="http://japhr.blogspot.com/">Chris Strom</a> for <a href="http://twitter.com/eee_c/status/4705290596">submitting</a> the challenge!</p>
]]></content:encoded>
			<wfw:commentRss>http://jonathanjulian.com/2009/10/i-just-entered-rpcfn-2/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

