<?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/"
	xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"
>

<channel>
	<title>John Desu &#187; Ruby on Rails</title>
	<atom:link href="http://www.johndesu.com/category/ruby-on-rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.johndesu.com</link>
	<description>culture, tech, music, and code</description>
	<lastBuildDate>Sat, 05 Jun 2010 04:52:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
<!-- podcast_generator="Blubrry PowerPress/1.0.9" mode="advanced" entry="normal" -->
	<itunes:summary>Monthly or so mixes of the latest electronic, progressive, and trance tunes.</itunes:summary>
	<itunes:author>John Dyer</itunes:author>
	<itunes:explicit>no</itunes:explicit>
	<itunes:image href="http://www.johndesu.com/images/podcastlogo.jpg" />
	<itunes:owner>
		<itunes:name>John Dyer</itunes:name>
		<itunes:email>lbrapid@gmail.com</itunes:email>
	</itunes:owner>
	<managingEditor>lbrapid@gmail.com (John Dyer)</managingEditor>
	<itunes:subtitle>Moving forward with the web and great music</itunes:subtitle>
	<itunes:keywords>trance,free,mixes,electronic,electro,progressive</itunes:keywords>
	<image>
		<title>John Desu &#187; Ruby on Rails</title>
		<url>http://www.johndesu.com/images/podcastlogo.jpg</url>
		<link>http://www.johndesu.com/category/ruby-on-rails/</link>
	</image>
	<itunes:category text="Music" />
	<itunes:category text="Technology">
		<itunes:category text="Podcasting" />
	</itunes:category>
		<item>
		<title>Missed out on RailsConf? Me too. Here&#8217;s how I caught up</title>
		<link>http://www.johndesu.com/2009/05/17/missed-out-on-railsconf-me-too-heres-how-i-caught-up/</link>
		<comments>http://www.johndesu.com/2009/05/17/missed-out-on-railsconf-me-too-heres-how-i-caught-up/#comments</comments>
		<pubDate>Sun, 17 May 2009 05:13:03 +0000</pubDate>
		<dc:creator>John Dyer</dc:creator>
				<category><![CDATA[Asides]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[david heinemeir hansson]]></category>
		<category><![CDATA[Git]]></category>
		<category><![CDATA[Github]]></category>
		<category><![CDATA[merb]]></category>
		<category><![CDATA[o'reilly]]></category>
		<category><![CDATA[rails magazine]]></category>
		<category><![CDATA[railsconf]]></category>

		<guid isPermaLink="false">http://www.johndesu.com/?p=244</guid>
		<description><![CDATA[I&#8217;m sure I&#8217;m not the only Rails developer who missed RailsConf 2009 due to a plethora of various reasons. Well, I didn&#8217;t let that hold me back from gaining as much information as possible from the Conference. Although these resources are pretty easy to find, I thought I would help you out by providing you [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://en.oreilly.com/rails2009/"><img class="alignnone" title="Railsconf 2009" src="http://assets.en.oreilly.com/1/event/24/rails2009_logo.gif" alt="Railsconf 2009" width="164" height="68" /></a></p>
<p>I&#8217;m sure I&#8217;m not the only Rails developer who missed RailsConf 2009 due to a plethora of various reasons. Well, I didn&#8217;t let that hold me back from gaining as much information as possible from the Conference. Although these resources are pretty easy to find, I thought I would help you out by providing you with some links.</p>
<p>First is the <a title="RailsConf 2009 Official Site" href="http://en.oreilly.com/rails2009/">official RailsConf site</a>, hosted by O&#8217;Reilly. This would be an obvious first choice for people, but I am still going to restate that there is a great deal of free content available here. Most of the keynotes and speeches are now up in pretty high-quality video and slides are available in PDF form for both the keynotes and most of the tutorials.</p>
<p>Next, if you&#8217;re like most people, you might not have enough time to watch the hours of videos or sort through all the slideshows available over at the RailsConf site. Well, you&#8217;re still in a great position to learn from those keynotes, as Nick Quaranto attended a ton of events at RailsConf and took great notes, which he<a title="RailsConf 2009 Notes" href="http://litanyagainstfear.com/blog/2009/05/05/railsconf-2009-notes/"> published here</a> on his blog <a title="Litany against fear" href="http://litanyagainstfear.com">litany against fear</a>. Some highlights include the <a href="http://litanyagainstfear.com/blog/2009/05/05/railsconf-2009-dhh-keynote">David Heinemeier Hansson keynote</a> on the future of Rails and the secret to being productive using Rails, some great keynotes about <a href="http://litanyagainstfear.com/blog/2009/05/05/railsconf-2009-smacking-git-around">git</a> and <a href="http://litanyagainstfear.com/blog/2009/05/05/railsconf-2009-a-morning-with-github">github</a>, and a <a href="http://litanyagainstfear.com/blog/2009/05/07/railsconf-2009-webrat-rails-testing-evolved">speech given</a> about testing with <a href="http://github.com/brynary/webrat/tree/master">Webrat</a>. Definitely worth checking out.</p>
<p>The final resource I&#8217;m providing related to RailsConf is from <a title="Rails Magazine" href="http://railsmagazine.com/">Rails Magazine</a>. They just published their <a href="http://railsmagazine.com/issues/2">second issue</a> and it is a special edition for RailsConf. I really am trying my best to support this magazine because I think it would be great to see this magazine grow into something great (not that it isn&#8217;t already) and be avaialable at bookstores and news stands. The big article goes over what&#8217;s coming to Rails 3 and details about the Merb and Rails merge. Oh, did I mention this magazine is free in digital form?</p>
<p>And while I&#8217;m at it, I thought I&#8217;d also point you over to a <a title="Githib pages for fun" href="http://www.quirkey.com/blog/2009/05/01/github-pages-for-fun-and-win/">very, very detailed article</a> about the benefit of building websites for projects on github and how things should be documented. I think if this is more heavily adopted, it would make life easier for developers using a lot of various gems and plugins. But at the same time I understand that this does take effort to create and most people aren&#8217;t exactly overflowing with free time. Either way, a good read that I though I&#8217;d share. I hope these resources help you to understand what happened at RailsConf and hopefully taught you something new.</p>
<img src="http://www.johndesu.com/?ak_action=api_record_view&id=244&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.johndesu.com/2009/05/17/missed-out-on-railsconf-me-too-heres-how-i-caught-up/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>29 Links and Resouces for learning Sinatra</title>
		<link>http://www.johndesu.com/2009/02/03/29-links-and-resouces-for-learning-sinatra/</link>
		<comments>http://www.johndesu.com/2009/02/03/29-links-and-resouces-for-learning-sinatra/#comments</comments>
		<pubDate>Tue, 03 Feb 2009 10:01:56 +0000</pubDate>
		<dc:creator>John Dyer</dc:creator>
				<category><![CDATA[Links]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[resources]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[sinatra]]></category>

		<guid isPermaLink="false">http://www.johndesu.com/2009/02/03/29-links-and-resouces-for-learning-sinatra/</guid>
		<description><![CDATA[Sinatra is considered a Ruby micro framework and is used for developing web applications on the fly! You can use it to develop small to medium applications or use it along with rails to create powerful web apps. Sinatra has a great homepage with plenty of examples on how to get started. To install, you [...]]]></description>
			<content:encoded><![CDATA[<p style="clear: both"><a title="Sinatra" href="http://www.sinatrarb.com">Sinatra</a> is considered a Ruby micro framework and is used for developing web applications on the fly! You can use it to develop small to medium applications or use it along with rails to create powerful web apps.</p>
<p style="clear: both">Sinatra has a great <a title="Sinatra homepage" href="http://www.sinatrarb.com">homepage</a> with plenty of examples on how to get started. To install, you can grab the sinatra gem or clone the <a href="http://github.com/sinatra/sinatra/tree/master">git repository</a>.</p>
<p style="clear: both">While the examples on the Sinatra site are great for building your first simple application, <a href="http://www.rubyinside.com">Ruby Inside</a> has put together a great list of links and resources for people interested in Sinatra.</p>
<p style="clear: both"><a href="http://www.rubyinside.com/sinatra-29-links-and-resources-for-a-quicker-easier-way-to-build-webapps-1371.html">Check it out over at Ruby Inside</a></p>
<img src="http://www.johndesu.com/?ak_action=api_record_view&id=101&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.johndesu.com/2009/02/03/29-links-and-resouces-for-learning-sinatra/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting Started With Rails Migrations Part 1: Creating Migrations</title>
		<link>http://www.johndesu.com/2009/01/13/getting-started-with-rails-migrations-part-1-creating-migrations/</link>
		<comments>http://www.johndesu.com/2009/01/13/getting-started-with-rails-migrations-part-1-creating-migrations/#comments</comments>
		<pubDate>Tue, 13 Jan 2009 06:19:59 +0000</pubDate>
		<dc:creator>John Dyer</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[ActiveRecord]]></category>
		<category><![CDATA[databases]]></category>
		<category><![CDATA[migrations]]></category>

		<guid isPermaLink="false">http://www.johndesu.com/?p=77</guid>
		<description><![CDATA[A migration is simply a Ruby source file in your application’s db/migrate directory. These files help to make small changes to the database extremely easy and quick. Want to add a table or rename a column? Write another migration and run rake db:migrate. With automatic versioning you are able to see the changes made to [...]]]></description>
			<content:encoded><![CDATA[<p>A migration is simply a Ruby source file in your application’s db/migrate directory. These files help to make small changes to the database extremely easy and quick. Want to add a table or rename a column? Write another migration and run <i>rake db:migrate. </i>With automatic versioning you are able to see the changes made to the model just by looking at the latest migration file. No more repetitive SQL queries. Now you can access your data in an understandable way right in your code. With that, let&#8217;s get coding!</p>
<p>First we can use either the rails generator to create a migration or use the model generator, which will also give us a migration file. Note: you could create these files by hand, but it is less error-prone and probably more efficient to use a built-in generator. </p>
<p>To create a migration with the model generator we would do something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="rails" style="font-family:monospace;">ruby script<span style="color:#006600; font-weight:bold;">/</span>generate model post
  exists app<span style="color:#006600; font-weight:bold;">/</span>models<span style="color:#006600; font-weight:bold;">/</span>
  exists test<span style="color:#006600; font-weight:bold;">/</span>unit<span style="color:#006600; font-weight:bold;">/</span>
  exists test<span style="color:#006600; font-weight:bold;">/</span>fixtures<span style="color:#006600; font-weight:bold;">/</span>
  create app<span style="color:#006600; font-weight:bold;">/</span>models<span style="color:#006600; font-weight:bold;">/</span>post.<span style="color:#9900CC;">rb</span>
  create test<span style="color:#006600; font-weight:bold;">/</span>unit<span style="color:#006600; font-weight:bold;">/</span>post_test.<span style="color:#9900CC;">rb</span>
  create test<span style="color:#006600; font-weight:bold;">/</span>fixtures<span style="color:#006600; font-weight:bold;">/</span>posts.<span style="color:#9900CC;">yml</span>
  create db<span style="color:#006600; font-weight:bold;">/</span>migrate
  create db<span style="color:#006600; font-weight:bold;">/</span>migrate<span style="color:#006600; font-weight:bold;">/</span><span style="color:#006666;">20090113055719</span>_create_posts.<span style="color:#9900CC;">rb</span></pre></div></div>

<p>To create a migration on its own we would do something similar to this:</p>

<div class="wp_syntax"><div class="code"><pre class="rails" style="font-family:monospace;">ruby script<span style="color:#006600; font-weight:bold;">/</span>generate migration add_category_column
exists db<span style="color:#006600; font-weight:bold;">/</span>migrate
create db<span style="color:#006600; font-weight:bold;">/</span>migrate<span style="color:#006600; font-weight:bold;">/</span><span style="color:#006666;">20090113055952</span>_add_category_column.<span style="color:#9900CC;">rb</span></pre></div></div>

<p>To run the migration we use the db:migrate task</p>

<div class="wp_syntax"><div class="code"><pre class="rails" style="font-family:monospace;">rake db:migrate</pre></div></div>

<p>When running the db:migrate Rake task, a <i>schema_migrations</i> table is looked for to keep track of migration versions. If one isn&#8217;t found it will be created on the fly. After each migration is run a row in the <i>schema_migration</i> table is added. </p>
<p>You can also use the db:migrate Rake task to force the database to a specific version by supplying it with the <i>Version=</i> parameter.</p>

<div class="wp_syntax"><div class="code"><pre class="rails" style="font-family:monospace;">rake db:migrate VERSION=<span style="color:#006666;">20090113055719</span></pre></div></div>

<p>To revert the database to it&#8217;s original state supply <i>Version=</i> paramter with 0.</p>

<div class="wp_syntax"><div class="code"><pre class="rails" style="font-family:monospace;">rake db:migrate VERSION=<span style="color:#006666;">0</span></pre></div></div>

<p>If you run a migration whose version is higher than the version of the current database, the migration will be applied. Somewhat differently, if you run a migration whose version is lower than the version of the current database, Rails will look for the migration file whose number matches the database version and undo it. </p>
<p>I hope this tutorial has helped you to begin to understand ActiveRecord and how useful migrations can be. In the next article in this series we look at what makes up a migration in more detail.</p>
<img src="http://www.johndesu.com/?ak_action=api_record_view&id=77&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.johndesu.com/2009/01/13/getting-started-with-rails-migrations-part-1-creating-migrations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting Started With Ruby on Rails: Resources (Paid and Free)</title>
		<link>http://www.johndesu.com/2009/01/11/getting-started-with-ruby-on-rails-resources-paid-and-free/</link>
		<comments>http://www.johndesu.com/2009/01/11/getting-started-with-ruby-on-rails-resources-paid-and-free/#comments</comments>
		<pubDate>Sun, 11 Jan 2009 21:08:00 +0000</pubDate>
		<dc:creator>John Dyer</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[peepcode]]></category>
		<category><![CDATA[rails 2]]></category>
		<category><![CDATA[resources]]></category>

		<guid isPermaLink="false">http://www.johndesu.com/?p=70</guid>
		<description><![CDATA[I have gone through all of my Ruby on Rails resources and have come up with a list of what I think are the best resources to get you started with your Ruby on Rails journey. This will be the first of a few lists about Ruby on Rails I will be posting over the [...]]]></description>
			<content:encoded><![CDATA[<p>I have gone through all of my Ruby on Rails resources and have come up with a list of what I think are the best resources to get you started with your Ruby on Rails journey. This will be the first of a few lists about Ruby on Rails I will be posting over the next week or two. Following the getting started list will be a list on intermediate resources, advanced resources, and finally a list of some commonly plugins and blogs that I really think will help boost your understanding of Ruby on Rails. So with that, let&#8217;s get started!</p>
<p><b>Free Resources<br /></b>
<ol>
<li>First you&#8217;ll probably want to get Ruby on Rails installed on your machine. To do this is quite simple and <a href="http://wiki.rubyonrails.org/rails/pages/GettingStartedWithRails">this website</a> will help you along the way. If you are on a relatively new mac, you probably already have Rails installed and therefore just running the command &#8216;gem install rails&#8217; from the terminal will get you the newest version of rails and all of it&#8217;s dependencies. More on this on the official <a href="http://rubyonrails.org/">Ruby on Rails website</a>.</li>
<li>Rolling With Ruby on Rails <a href="http://www.onlamp.com/pub/a/onlamp/2005/01/20/rails.html">Part 1</a> and <a href="http://www.onlamp.com/pub/a/onlamp/2005/03/03/rails.html">Part 2</a> &#8211; This is a slightly outdated tutorial as it was written in 2005, but it still serves as a great introduction to the language of ruby and the framework rails provides.&nbsp;</li>
<li><a href="http://www.slash7.com/articles/2005/01/24/really-getting-started-in-rails">Really Getting Started with Rails</a> &#8211; Amy Hoy over at <a href="http://www.slash7.com">Slash7</a> has put together a great guide that not only covers the the basics of RoR, but also introduces the reader to the basic concepts of the Ruby scripting language.</li>
<li><a href="http://www.alistapart.com/articles/gettingstartedwithrubyonrails">Getting Started With Ruby on Rails</a> &#8211; The excellent A List Apart wrote an article not very long ago that shows the benefits of using RoR for a web project. It introduces the reader to the basics of ruby and many concepts of the rails MVC framework.</li>
<li><a href="http://developer.apple.com/tools/rubyonrails.html">Using Ruby on Rails for Web Development on Mac OSX</a> &#8211; Apple has written an article on getting started using ruby on rails with a fresh install of Mac OS X. It is a great tutorial that takes you through the creation of a basic RoR web application.</li>
<li><a href="http://nettuts.com/videos/screencasts/ruby-on-rails-week-4/">Ruby on Rails from Scratch</a> &#8211; Probably my favorite of all the free tutorials I have listed. This is a four part series of very visual tutorials for learning RoR. I know most people are visual learners, so this series is great for you. In fact, parts of the series are video tutorials. Definitely worth checking out.</li>
<li><a href="http://api.rubyonrails.org/">Rails Framework Documentation</a> &#8211; This is the Rails API. Get familiar with it because it will become extremely useful the more you learn to love it.</li>
</ol>
<p><span id="more-70"></span>So I would consider those the best of the best free tutorials available. But free tutorials will only get you so far. The following is a list of paid resources that I would definitely consider checking out.</p>
<p><b>Paid Resources<br /></b>
<ol>
<li><a href="http://peepcode.com/">Peepcode</a> &#8211; Definitely my favorite, favorite resource for learning the workings of Ruby on Rails. They cover many advanced topics but also basic topics as well. I would definitely check out Rails 2 from Scratch <a href="https://peepcode.com/products/rails-from-scratch-part-i">Part 1</a> and <a href="https://peepcode.com/products/rails-from-scratch-part-ii">Part 2</a> if you are just getting started with Rails. Each screencast is $9, but money can be saved if you buy credit packs or a yearly subscription. It is also worth checking out some of the PDFs they have about Rails 2 and Git.</li>
<li><a href="http://www.pragprog.com/titles/rails3/agile-web-development-with-rails-third-edition">Agile Web Development With Rails</a> &#8211; This is an amazing book published by the Pragmatic Programmers (well it actually hasn&#8217;t been published yet) that can be purchased as a beta pdf. What is a beta pdf you might ask? A beta pdf is a digital copy of the book that is being updated as the book is being corrected and added to (as rails changes). Each time they release a new version of the book, you can download it again and have the newest content available. Basically, the first half of the book takes you through the creation of a complete rails application and the second half is a very deep look into the rails API with examples and explanations galore.</li>
<li><a href="http://www.amazon.com/Rails-Way-Addison-Wesley-Professional-Ruby/dp/0321445619">The Rails Way</a> &#8211; Another great book that teaches you tons of great things on Rails 2. For me it is second only to Agile Web Development With Rails.</li>
</ol>
<p>Alright, I hope that gets you started with Ruby on Rails. I will be posting another list of Rails resources and tips later this week that will give you an idea of how to make the leap from novice to intermediate Rails programmer. </p>
<img src="http://www.johndesu.com/?ak_action=api_record_view&id=70&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.johndesu.com/2009/01/11/getting-started-with-ruby-on-rails-resources-paid-and-free/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>RJS Demystified WIth Pretty Colors! Also 5 RoR Tips for Beginners&#8230;</title>
		<link>http://www.johndesu.com/2008/10/16/rjs-demystified-with-pretty-colors-also-5-ror-tips-for-beginners/</link>
		<comments>http://www.johndesu.com/2008/10/16/rjs-demystified-with-pretty-colors-also-5-ror-tips-for-beginners/#comments</comments>
		<pubDate>Thu, 16 Oct 2008 20:42:13 +0000</pubDate>
		<dc:creator>John Dyer</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[rjs]]></category>

		<guid isPermaLink="false">http://www.johndesu.com/?p=49</guid>
		<description><![CDATA[Amy Hoy over at Slash7 has put together an amazing cheatsheet for RJS (ruby javascript) documents. It is 3 pages long and uses lots and lots of bright colors to illustrate clearly how rjs is interpretated. She asks viewers to resist the urge of putting it on Digg yet, as her server is not ready [...]]]></description>
			<content:encoded><![CDATA[<p><img style="float: left; margin-top: 10px; margin-bottom: 10px; margin-right: 10px;" src="http://slash7.com/assets/2006/10/8/cheat-sheet-teaser-r.png" border="0" />Amy Hoy over at Slash7 has put together an amazing cheatsheet for RJS (ruby javascript) documents. It is 3 pages long and uses lots and lots of bright colors to illustrate clearly how rjs is interpretated. </p>
<p>She asks viewers to resist the urge of putting it on Digg yet, as her server is not ready to take another &#8220;Digging&#8221; quite yet.</p>
<p>View Amy&#8217;s post <a target="_blank" href="http://www.slash7.com/articles/2006/10/8/rjs-demistified-with-pretty-colors">here</a></p>
<p>View the cheatsheet directly <a href="http://slash7.com/assets/2006/10/8/RJS-Demistified_Amy-Hoy-slash7_1.pdf">here</a></p>
<p>I would also like to mention a blog post I found today on <a target="_blank" href="http://www.railsforum.com">Rails Forum</a> which contains five tips to help beginners really get started with Ruby on Rails. Check it out <a target="_blank" href="http://railsforum.com/viewtopic.php?id=17705">here</a>.</p>
<p>That&#8217;s it for now, but be sure to check back soon as there should be a tutorial on getting started with Adobe AIR up soon. I will then move onto more advanced topics and show you how to develop a basic twitter AIR app over the next few weeks. (or when mid-terms permit me to)</p>
<img src="http://www.johndesu.com/?ak_action=api_record_view&id=49&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.johndesu.com/2008/10/16/rjs-demystified-with-pretty-colors-also-5-ror-tips-for-beginners/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ruby On Rails: Meaningful (and beautiful) URLs</title>
		<link>http://www.johndesu.com/2008/10/15/ruby-on-rails-meaningful-and-beautiful-urls/</link>
		<comments>http://www.johndesu.com/2008/10/15/ruby-on-rails-meaningful-and-beautiful-urls/#comments</comments>
		<pubDate>Thu, 16 Oct 2008 03:48:40 +0000</pubDate>
		<dc:creator>John Dyer</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.johndesu.com/?p=40</guid>
		<description><![CDATA[This tutorial is going to take you through what it takes to make your URLs easy to remember and meaningful. Great examples of sites that implement this well are Flickr and Delicious. We are going to first take a look at the Routes framework in the Action Controller and see what options it gives us. [...]]]></description>
			<content:encoded><![CDATA[<p>This tutorial is going to take you through what it takes to make your URLs easy to remember and meaningful. Great examples of sites that implement this well are Flickr and Delicious. We are going to first take a look at the Routes framework in the Action Controller and see what options it gives us. I am going to assume basic knowledge of Ruby on Rails and am going to assume that your are starting with a newly generated application. (NOTE: I am using Rails 2.1.1)</p>
<p>Routes in Ruby on Rails allow you to map incoming URLs to specific controllers, actions, and parameters in your application. Routes are written in pure ruby and can be found in the file <i>config/routes.rb</i> in your application&#8217;s root directory. Upon generating a new application using <i>rails appname</i>, some default routes are created for you as shown below (comments have been removed):</p>
<blockquote>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="rails" style="font-family:monospace;"><span style="color:#6666ff; font-weight:bold;">ActionController::Routing::Routes</span>.<span style="color:#9900CC;">draw</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>map<span style="color:#006600; font-weight:bold;">|</span>
    map.<span style="color:#9900CC;">connect</span> <span style="color:#996600;">':controller/:action/:id'</span>
    map.<span style="color:#9900CC;">connect</span> <span style="color:#996600;">':controller/:action/:id.:format'</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p></p></blockquote>
<p><span id="more-40"></span>Routes are created using the <i>connect()</i> method. For more information on the arguments <i>connect()</i> can take, <a target="_blank" href="http://api.rubyonrails.org/classes/ActionController/Routing.html">see here</a>. Now that you have a handle on what routes are and what they do, let&#8217;s make one of our own.</p>
<p>Now for lack of an example, let&#8217;s imagine that we are creating a site that let&#8217;s users post and share songs they have made. We have a controller called SongController that contains most of the logic of the application. Our controller, SongController, has an action, display(), that can search for and display songs based on assorted criteria, like the song&#8217;s author.</p>
<p>First, I am going to show you how to create a route that will let users display all songs created by a specific author. Let&#8217;s assume our site is called SongShare (assuming the application is installed at <i>songshare.com</i>) We want a URL for a user <i>JohnD </i>to look like this: <i>songshare.com/johnd</i> Because it would be off-topic to make a full application and display the code here, I am going to show a temporary version of our <i>list</i> action. This will raise an exception, passing any supplied parameters. This causes the application to fail and show these parameters in the browser. I won&#8217;t go into detail of how to create the search, as it doesn&#8217;t pertain to this and the parameters are really all we need for this example. </p>
<blockquote>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="rails" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> SongController <span style="color:#006600; font-weight:bold;">&lt;</span> ApplicationController
  <span style="color:#9966CC; font-weight:bold;">def</span> list
      <span style="color:#CC0066; font-weight:bold;">raise</span> params.<span style="color:#9900CC;">inspect</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

</blockquote>
<p>Now, let&#8217;s create our route. Open up <i>config/routes.rb</i> again and add the following line after the routes already provided:</p>
<blockquote>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="rails" style="font-family:monospace;">map.<span style="color:#9900CC;">connect</span> <span style="color:#996600;">':user'</span>, <span style="color:#ff3333; font-weight:bold;">:controller</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'song'</span>, 
                       <span style="color:#ff3333; font-weight:bold;">:action</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'list'</span>, 
                       <span style="color:#ff3333; font-weight:bold;">:filter</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'user'</span></pre></td></tr></table></div>

<p></p></blockquote>
<p>If you start your local server running on the default port of 3000, you should now be able to go to http://localhost:3000/johnd and see an error page with the heading <i>RuntimeError in SongController#list</i>. This is a good thing (for our purposes at least). You now know that your page request was routed to the <i>list</i> action previously created. Below the heading, you should see a listing of the request&#8217;s parameters. You should see four items here: the user parameter, the action, the filter parameter, and the controller.</p>
<p>That&#8217;s all great, but let&#8217;s get more specific now. What if we wanted to limit our search to songs that are posted by a specific user and tagged as electro. Let&#8217;s modify the previous route declaration to look like the following (NOTE: There are multiple ways to do this, it&#8217;s up to you!):</p>
<blockquote>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="rails" style="font-family:monospace;">map.<span style="color:#9900CC;">connect</span> <span style="color:#996600;">':user/:tag'</span>, <span style="color:#ff3333; font-weight:bold;">:controller</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'song'</span>, 
  		<span style="color:#ff3333; font-weight:bold;">:action</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'list'</span>, 
  	        <span style="color:#ff3333; font-weight:bold;">:filter</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'user'</span>,
  		<span style="color:#ff3333; font-weight:bold;">:tag</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">' '</span></pre></td></tr></table></div>

</blockquote>
<p>This route will match URLs such as <i>http://localhost:3000/johnd/electro</i> and populate both the :user and :tag parameters. If no tag is specified, the route will still match, and an empty string will be placed in the :tag parameter.</p>
<p>Now let&#8217;s make a route to display the top-ranked songs at <i>http://localhost:3000/popular</i>. We will also allow tags to be supplied as we did in the previous example. Add the following to <i>routes.rb</i>:</p>
<blockquote>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="rails" style="font-family:monospace;">map.<span style="color:#9900CC;">connect</span> <span style="color:#996600;">'popular/:tag'</span>, <span style="color:#ff3333; font-weight:bold;">:controller</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'song'</span>,
  			<span style="color:#ff3333; font-weight:bold;">:action</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'list'</span>,
  			<span style="color:#ff3333; font-weight:bold;">:tag</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">''</span>,
  			<span style="color:#ff3333; font-weight:bold;">:filter</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'popular'</span></pre></td></tr></table></div>

</blockquote>
<p>This must go above the existing routes in <i>routes.rb</i> or else the wrong parameters will be populated. This is because the Routes engine processes routes in the order they appear in the file and there is nothing to distinguish the word popular from a user&#8217;s name.</p>
<p>Finally, let&#8217;s allow you to display all the songs that were added on a specific day. Put this route <b>before</b> the user route:</p>
<blockquote>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="rails" style="font-family:monospace;">map.<span style="color:#9900CC;">connect</span> <span style="color:#996600;">'daily/:month/:day/:year'</span>,
  			<span style="color:#ff3333; font-weight:bold;">:controller</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'song'</span>,
  			<span style="color:#ff3333; font-weight:bold;">:action</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'list'</span>,
  			<span style="color:#ff3333; font-weight:bold;">:filter</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'daily'</span>,
  			<span style="color:#ff3333; font-weight:bold;">:month</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'Time.now.month'</span>,
  			<span style="color:#ff3333; font-weight:bold;">:day</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'Time.now.day'</span>,
  			<span style="color:#ff3333; font-weight:bold;">:year</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'Time.now.year'</span>,
  			<span style="color:#ff3333; font-weight:bold;">:requirements</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span>
  				<span style="color:#ff3333; font-weight:bold;">:year</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">/</span>\d<span style="color:#006600; font-weight:bold;">+/</span>,
  				<span style="color:#ff3333; font-weight:bold;">:day</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">/</span>\d<span style="color:#006600; font-weight:bold;">+/</span>,
  				<span style="color:#ff3333; font-weight:bold;">:month</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">/</span>\d<span style="color:#006600; font-weight:bold;">+/</span>
			<span style="color:#006600; font-weight:bold;">&#125;</span></pre></td></tr></table></div>

</blockquote>
<p>This route will accept URLs such as http://localhost:3000/daily/08/18/2008 and populates the :month, :day, and :year parameters. The :requirements parameter we specified that the year, day, and month must be numeric digits for the route to match.</p>
<p>And there you have it, how to make pretty URLs using routes in rails. If anyone has any other methods or questions, please post in the comments.</p>
<p>[ad#adroll-1]</p>
<img src="http://www.johndesu.com/?ak_action=api_record_view&id=40&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.johndesu.com/2008/10/15/ruby-on-rails-meaningful-and-beautiful-urls/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
