How should I fix a problem with uncountable resources in polymorphic_url?

I've run across a bug with polymorphic_url, which I have reported

The gist of the problem is that passing an uncountable resource (such
as an AR Model called Sheep) causes the method to throw an exception.
The reason for this is because when you map an uncountable resource,
you pass in a :singular option. Something like:

map.resources :sheep, :singular => :sheep_instance

That generates helpers called sheep_instance_url,
edit_sheep_instance_url, etc.

This becomes an issue for polymorphic_url as it tries to call the
named route helper, but has no good way of looking up the appropriate
helper. polymorphic_url consults RecordIdentifier, which will try to
get the singular name of the model. When this is done for an
uncountable model the singular and plural name are the same and
build_named_route_call will generate the wrong name for the helper (in
the example, if you try polymorphic_url(@sheep) it will try to call
sheep_url, when it should be calling sheep_instance_url). I don't see
any good way on checking what the named_routes for an uncountable
resource are...

Does anyone have any suggestions for fixing this bug?


I've run into this problem also. I'd assume this method[1] would have
to be patched so it knows about the :singular option on a resource.
I'm new to the Rails internals, so I'm not sure exactly how to
accomplish that. I'll keep digging though.



Zach Carter

A similar problem also applies to using polymorphic_url with singular resource:

As I said in my comment, I can't see how polymorphic_url could know whether an AR instance is mapped to a singular resource path. For the case of an uncountable resource polymorphic_url should be able to detect whether the AR model is uncountable and call the appropriate url helper.


Right, it needs the value you specify for the :singular option on the
resource to call the correct url helper. For now I've patched it to
append _instance if singular and plural are the same, because that's
the idiom I use. Ideally it would be able to get the value from


Zach Carter