<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>something learned comments on How To: Uncountable Names in RESTful Routes</title>
    <link>http://www.somethinglearned.com/</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>something learned comments</description>
    <item>
      <title>"How To: Uncountable Names in RESTful Routes" by trevor</title>
      <description>&lt;p&gt;A couple of times I&amp;#8217;ve noticed people saying that uncountable names (like sheep and fish) can&amp;#8217;t be used with resource routes in Rails.  Well, they can.&lt;/p&gt;


&lt;code&gt;&lt;pre&gt;
# in config/routes.rb
map.resources :fish
&lt;/pre&gt;&lt;/code&gt;

	&lt;p&gt;In the above example there is a conflict between the generated url helpers for the &amp;#8216;fish&amp;#8217; collection and the generated url helpers for &lt;em&gt;members&lt;/em&gt; of the &amp;#8216;fish&amp;#8217; collection.  Because &amp;#8216;fish&amp;#8217; is uncountable, both are called &lt;code&gt;fish_path&lt;/code&gt; or &lt;code&gt;fish_url&lt;/code&gt;.  And because of the way routes and url helpers are created in a &lt;code&gt;map.resources&lt;/code&gt; call, the member url helpers override the collection ones.&lt;/p&gt;


	&lt;p&gt;So using the above example, calling &lt;code&gt;fish_path()&lt;/code&gt; raises an error like:&lt;/p&gt;


&lt;p&gt;&lt;code&gt;
ActionController::RoutingError: fish_url failed to generate from {:controller=&amp;gt;"fish", :action=&amp;gt;"show"} - you may have ambiguous routes, or you may need to supply additional parameters for this route.  content_url has the following required parameters: ["fish", :id] - are they all satisifed?
&lt;/code&gt;&lt;/p&gt;

	&lt;p&gt;Thankfully that&amp;#8217;s not the end of it. You just have to add a &lt;code&gt;:singular&lt;/code&gt; argument when defining your resources:&lt;/p&gt;


&lt;code&gt;&lt;pre&gt;
# in config/routes.rb
map.resources :fish, :singular =&amp;gt; :fish_instance

# in your code
fish_path() #=&amp;gt; /fish
new_fish_instance_path() #=&amp;gt; /fish/new
fish_instance_path(1) #=&amp;gt; /fish/1
edit_fish_instance_path(1) #=&amp;gt; /fish/1;edit
&lt;/pre&gt;&lt;/code&gt;

	&lt;p&gt;That&amp;#8217;s all.&lt;/p&gt;

</description>
      <pubDate>Mon, 19 Mar 2007 00:03:23 EST</pubDate>
      <guid>&lt;a href="/articles/2007/03/19/how-to-uncountable-names-in-restful-routes"&gt;How To: Uncountable Names in RESTful Routes&lt;/a&gt;</guid>
      <link>&lt;a href="/articles/2007/03/19/how-to-uncountable-names-in-restful-routes"&gt;How To: Uncountable Names in RESTful Routes&lt;/a&gt;</link>
    </item>
  </channel>
</rss>
