Singular Resources May 18th, 2007

This just bit me in the butt and I had trouble figuring out why.

If you want to use singular resources in rails (ie session) then you need to specify them as:

map.resource :session
NOTE: the resource is singular.

If you don't you'll get an error akin to:
session_url failed to generate from {:controller=>"session", :action=>"show"} - you may have ambiguous routes, or you may need to supply additional parameters for this route. content_url has the following required parameters: ["session", :id] - are they all satisfied?

It was driving me nuts. Easy to overlook and hard to find info from the googles.

1 Response to “Singular Resources”

  1. Kerry Buckley Says:
    Thank you! I had to read your tip several times (I found it by googling for "you may have ambiguous routes") until I realised that I'd made the exact same mistake -- writing "map.resources" instead of "map.resource". I'd been banging my head against the wall trying to figure out why my singular session resource wasn't working after upgrading from 1.2.1 and changing it from sessions.

Sorry, comments are closed for this article.