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.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---