Use url_for with singleton resources?

Has anyone had any success with url_for and singleton resources?

I have a singleton forum nested under both groups and places:
map.resources :groups do |group|
group.resource :forum
map.resources :places do |group|
group.resource :forum

So I have paths like /groups/123/forum and /places/456/forum.

In the forum controller, I do what essentially amounts to
@owner = Group.find_by_id(params[:group_id]) ||
so that @owner points to the group or place that has the forum in

In the forum views, I want a link that is polymorphic in relation to
@owner: it should resolve into group_forum_path( or
place_forum_path( depending on the value of @owner.

I’ve tried url_for([@owner,]), but I get this error: “You
have a nil object when you didn’t expect it! The error occurred while
evaluating nil.to_sym”. Debugging it a bit, I find that the method
name is correctly resolved into group_forum_path, but this method is
then sent both arguments, where it should only be sent the @owner.

Is this a bug? Am I using url_for incorrectly? Anyone have a solution?

For now, I wrote my own url helper to work around it. I might try to
fix url_for if I find the time, but first I want to find out if it is
in fact broken.

On Aug 12, 1:19 am, Henrik N [email protected] wrote:

Has anyone had any success with url_for and singleton resources?

So if I patch like, I can do e.g.
polymorphic_url([@parent, @forum], :singleton => true, :routing_type
=> :path)
In practice I’d wrap it.

Is there some way to figure out if the generated route is a singleton,
though, so you don’t have to specify it manually like this? I found /
which makes use of “plural_route”, but a grep in edge doesn’t turn up
anything of the sort. Google only finds the diff in question.