<?xml version="1.0" encoding="UTF-8"?>
<article>
  <body>I think that the complex Rails applications
such as maintained over years tend to have messy config/routes.
Today I'd like to introduce a simple way to keep them clean.

The way is really simple. Use with_options for each controller with prefix options.

rails&gt;&gt;
map.with_options(:controller =&gt; 'posts',
    :name_prefix =&gt; 'posts_',
    :path_prefix =&gt; 'posts') do |posts|
  # posts_rss_path =&gt; 'posts/rss'
  posts.rss 'rss', :action =&gt; 'rss'
end
&lt;&lt;--

Still complex?
Okey, I have written the plugin for you.

 * [map_with_controller](http://svn.s21g.com/public/rails/plugins/map_with_controller/)

With this plugin, you can draw the routes belonging to some controller like this.

rails&gt;&gt;
map.with_controller('posts') do |posts|
  posts.rss # posts_rss_path =&gt; 'posts/rss'
end
&lt;&lt;--

As you can see, there's one more thing.
I have also installed MapperWithController class into RouteSet at this plugin for making named routes be completely DRY.

rails&gt;&gt;
class MapperWithController
  def initialize(mapper)
    @mapper = mapper
  end

  def method_missing(name, *args, &amp;block)
    path, *args = args
    path ||= name.to_s
    args.unshift path
    @mapper.send name, *args, &amp;block
  end
end
&lt;&lt;--

`map.namespace :posts` does nearly same thing, but it couldn't be used for this purpose because of it is optimized to making namespaces for a routing.
</body>
  <cached-tag-list>rails howto routes</cached-tag-list>
  <comments-count type="integer">0</comments-count>
  <created-at type="datetime">2008-03-14T19:00:30+00:00</created-at>
  <daily-archive-id type="integer">488</daily-archive-id>
  <filter-type>blue_stole</filter-type>
  <id type="integer">452</id>
  <monthly-archive-id type="integer">46</monthly-archive-id>
  <pdf-digest nil="true"></pdf-digest>
  <permalink>/articles/452</permalink>
  <published-at type="datetime">2008-03-14T19:00:00+00:00</published-at>
  <secret>46007f2f-ef9f-459b-919b-063bffc74afd</secret>
  <title>How to draw cleanly controller specific routes.</title>
  <updated-at type="datetime">2008-03-15T01:57:46+00:00</updated-at>
  <user-id type="integer">9</user-id>
</article>
