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 end map.resources :places do |group| group.resource :forum end
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]) || Place.find_by_id(params[:place_id]) so that @owner points to the group or place that has the forum in question.
In the forum views, I want a link that is polymorphic in relation to @owner: it should resolve into group_forum_path(@owner.id) or place_forum_path(@owner.id) depending on the value of @owner.
I've tried url_for([@owner, @owner.forum]), 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.