<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
  <title>andthennothing.net: Routes - URLs on Rails</title>
  <subtitle type="html">&amp;ldquo;first there was a three-legged monkey...&amp;rdquo;</subtitle>
  <id>tag:andthennothing.net,2005:Typo</id>
  <generator uri="http://typo.leetsoft.com" version="4.0">Typo</generator>
  <link href="http://andthennothing.net/xml/atom10/article/284/feed.xml" rel="self" type="application/xml+atom"/>
  <link href="http://andthennothing.net/archives/2005/10/07/routes-urls-on-rails" rel="alternate" type="text/html"/>
  <updated>2005-12-18T03:19:08+00:00</updated>
  <entry>
    <author>
      <name>Jonas Bengtsson</name>
      <email>jonas.b@home.se</email>
    </author>
    <id>urn:uuid:03c9481f-970f-4acd-96b2-01d2a12a4e17</id>
    <published>2005-10-07T17:18:00+00:00</published>
    <updated>2005-12-18T03:19:08+00:00</updated>
    <title>Routes - URLs on Rails</title>
    <link href="http://andthennothing.net/archives/2005/10/07/routes-urls-on-rails" rel="alternate" type="text/html"/>
    <category term="typo" scheme="http://andthennothing.net/tags/284"/>
    <category term="rails" scheme="http://andthennothing.net/tags/284"/>
    <category term="customization" scheme="http://andthennothing.net/tags/284"/>
    <content type="html">&lt;p&gt;As I was getting ready to get this blog out the door I wanted to change the permalinks for the entries. Normally on a &lt;a href="http://typo.leetsoft.com/trac/wiki/TypoPowered"&gt;Typo powered&lt;/a&gt; blog the entries are places under &lt;tt&gt;/articles/YYYY/MM/DD/name/&lt;/tt&gt;, but I wanted to change from &lt;tt&gt;articles&lt;/tt&gt; to &lt;tt&gt;archives&lt;/tt&gt;. So I started updating &lt;tt&gt;config/routes.rb&lt;/tt&gt; and all the places where links were created (which is quite a few). I actually got a little angry that they didn&amp;#8217;t use custom helpers to generate all links, since it would be much easier to make the change in on place (putting them together with the routes would be even better, I thought, to honor &lt;acronym title="Don&amp;#8217;t Repeat Yourself"&gt;DRY&lt;/acronym&gt;).&lt;/p&gt;


	&lt;p&gt;But somehow I realised that Rails was cleverer than that. Actually, routing works both ways &amp;#8211; both for incoming requests and for &lt;span class="caps"&gt;URL&lt;/span&gt; generation. &lt;a href="http://api.rubyonrails.com/classes/ActionController/Base.html#M000170"&gt;url_for&lt;/a&gt; (which is used to create URLs for links etc.) uses the routing to create the correct URLs. So to change from &lt;tt&gt;articles&lt;/tt&gt; to &lt;tt&gt;archives&lt;/tt&gt; all that was needed was to change &lt;tt&gt;config/routes.rb&lt;/tt&gt; and everything worked. I think it&amp;#8217;s neat with separation between &lt;span class="caps"&gt;URL&lt;/span&gt; design and controller names!&lt;/p&gt;


	&lt;p&gt;Rails&amp;#8217; &amp;#8220;convention over configuration&amp;#8221; hides some of its neatness so you&amp;#8217;ll have to do some digging.&lt;/p&gt;</content>
  </entry>
</feed>
