<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="/stylesheets/rss.css" type="text/css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>The Dev Blog: Modules and Routes</title>
    <link>http://devblog.famundo.com/articles/2006/01/31/modules-and-routes</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>Putting Family Management on Rails!</description>
    <item>
      <title>Modules and Routes</title>
      <description>&lt;p&gt;Here's a little something for rails novices. Might save you some time and pain.&lt;/p&gt;

&lt;p&gt;I wanted nice URLs for my application, and one of the important parts was really short URLs for the main parts of the application. So you can do: http://www.famundo.com/library and get to the library module. Or http://www.famundo.com/photos to get to the library/photos area of the application.
That's easy with routes. In routes.rb I just had to add entries like:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;map.connect 'library'  , :controller =&gt; 'library_center', :action =&gt; 'show'
map.connect 'photos'   , :controller =&gt; 'my_pictures', :action =&gt; 'show'
map.connect 'blog'     , :controller =&gt; 'personal_blogs', :action =&gt; 'show'
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;But my system has a further complication. I use modules to separate the different parts of the application, so that everything is nicely organized in development. So for my maps I used:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;map.connect 'library'  , :controller =&gt; 'library/library_center', :action =&gt; 'show'
map.connect 'photos'   , :controller =&gt; 'library/my_pictures', :action =&gt; 'show'
map.connect 'blog'     , :controller =&gt; 'library/personal_blogs', :action =&gt; 'show'
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;At first it seemed to work fine, but when I got deeper in to the controllers actions, the resulting URLs where all messed up. After some work and some help on the list, the solution was VERY simple. I was missing an initial slash in my routes! When referencing the controller inside the module, I needed to add a leading slash. So that the routes are now working with:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;map.connect 'library'  , :controller =&gt; '/library/library_center', :action =&gt; 'show'
map.connect 'photos'   , :controller =&gt; '/library/my_pictures', :action =&gt; 'show'
map.connect 'blog'     , :controller =&gt; '/library/personal_blogs', :action =&gt; 'show'
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Ah, what a small &lt;em&gt;{color:red}/&lt;/em&gt; can do!&lt;/p&gt;</description>
      <pubDate>Tue, 31 Jan 2006 19:19:00 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:5dd9b35584e660919ba0abd9b126ede6</guid>
      <author>guy.naor@famundo.com (Guy Naor)</author>
      <link>http://devblog.famundo.com/articles/2006/01/31/modules-and-routes</link>
      <category>Rails</category>
      <trackback:ping>http://devblog.famundo.com/articles/trackback/2</trackback:ping>
    </item>
  </channel>
</rss>
