Currently, polymorphic_url can be called behind-the-scenes like this: <%= link_to @person.name, [EMAIL PROTECTED], @person] %>
which generates http://www.example.com/companies/1/people/5 But if you want to create a link to /companies/1/people/new, / companies/1/people/5/edit, /companies/1/people.atom, etc., you need to call polymorphic_url (specifically, new_polymorphic_url, edit_polymorphic_url and formatted_polymorphic_url) -- example: <%= link_to 'New Person', new_polymorphic_url [EMAIL PROTECTED], @person] %> (...although currently, new_polymorphic_url fails with multiple arguments because polymorphic_url doesn't call the correct named route; I've fixed this here: http://dev.rubyonrails.org/ticket/8719 ) The real gain for me is, when you've got a view that supports scoping of the resource by different parents, you can avoid putting in logic to build links appropriately, and just do: <%= link_to 'New Person', new_polymorphic_url [EMAIL PROTECTED], @person] %> ... and the link will either be to /categories/1/people/new or / companies/19/people/new, depending upon if @parent is set to a Category or Company. And with this patch -- http://dev.rubyonrails.org/ticket/8705 -- if @parent is nil, you'll just get /people/new This seems useful -- link_to can accommodate any nesting situation without wrapping it up in a custom helper, just so that the correct named route can be called. On Jun 22, 3:31 pm, Jonathan Vaught <[EMAIL PROTECTED]> wrote: > On Jun 22, 3:18 pm, Josh Peek <[EMAIL PROTECTED]> wrote: > > > IMHO, polymorphic_path and polymorphic_url should go > > protected from direct calls. > > I agree. DHH said earlier that he thought url_for should never be > called explicitly; I won't go that far but I do think that > polymorphic_url should stay behind the scenes. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
