I''ve reopened ticket #6432, which patched simply_helpful to allow polymorphic URL generation for nested resources. Since simply_helpful has been merged into core, I rewrote the patch for ActionPack. It implements the following usage: # Routes.rb map.resources :workshops do |w| w.resources :sessions end # View <%= url_for([@workshop, @session]) %> <%= link_to(''Session'', [@workshop, @session]) %> <% form_for([@workshop, @session] do |f| %> # ... <% end %> http://dev.rubyonrails.org/ticket/6432 Thoughts? -Jonathan. --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
On 6/5/07, Jonathan Vaught <jonathan.vaught@gmail.com> wrote:> I''ve reopened ticket #6432, which patched simply_helpful to allow > polymorphic URL generation for nested resources. > > Since simply_helpful has been merged into core, I rewrote the patch > for ActionPack. It implements the following usage: > > # Routes.rb > map.resources :workshops do |w| > w.resources :sessions > end > > # View > <%= url_for([@workshop, @session]) %> > <%= link_to(''Session'', [@workshop, @session]) %> > <% form_for([@workshop, @session] do |f| %> > # ... > <% end %> > > http://dev.rubyonrails.org/ticket/6432 > > Thoughts?Looks great. Thanks Jonathan! jeremy --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
On Jun 5, 11:24 am, Jonathan Vaught <jonathan.vau...@gmail.com> wrote:> # View > <%= url_for([@workshop, @session]) %> > <%= link_to(''Session'', [@workshop, @session]) %> > <% form_for([@workshop, @session] do |f| %> > # ... > <% end %>Can you explain this a little more? I understand polymorphics, but still trying to grok simply_helpful, so I''m not exactly sure what these arrays are doing in there. (Feel free to push this thread to rubyonrails-talk if that''s more appropriate). Thanks! Jeff --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Essentially, simply_helpful''s form_for helper will try to figure out the correct URL that it should be POSTing to based on the object you give it. If the form is for @workshop (<% form_for @workshop do ... %>), with is an instance of Workshop, the form will POST to /workshops (or PUT to /workshops/123 if editing a saved instance). If you were editing a nested resource (i.e. /workshops/123/sessions/456), the url generation in simply_helpful did not correctly use those nested resources. By passing an array of objects, it''s now possible for the form action url to be inferred based on the classes of the objects in that array. I haven''t looked at how the patch here actually works, but the logic might be something like this: 1. take the last element of the array, since that''s the most-inner of the nested resources. In this case, that''s @session 2. infer the named route method based on that object''s class, and then pass the array as arguments to that array. So, what ends up being called is sessions_path(@workshop, @session) which is the correct URL for this resource. HTH, James On 6/6/07, Jeff <cohen.jeff@gmail.com> wrote:> > On Jun 5, 11:24 am, Jonathan Vaught <jonathan.vau...@gmail.com> wrote: > > # View > > <%= url_for([@workshop, @session]) %> > > <%= link_to(''Session'', [@workshop, @session]) %> > > <% form_for([@workshop, @session] do |f| %> > > # ... > > <% end %> > > Can you explain this a little more? I understand polymorphics, but > still trying to grok simply_helpful, so I''m not exactly sure what > these arrays are doing in there. > > (Feel free to push this thread to rubyonrails-talk if that''s more > appropriate). > > Thanks! > Jeff > > > > >-- * J * ~ --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
There''s a bug in the version of this patch that was applied to edge. I reopened the ticket and submitted a fix. http://dev.rubyonrails.org/ticket/6432 --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
On Jun 6, 5:59 am, "James Adam" <james.a...@gmail.com> wrote:> Essentially, simply_helpful''s form_for helper will try to figure out > the correct URL that it should be POSTing to based on the object you > give it. If the form is for @workshop (<% form_for @workshop do ... > %>), with is an instance of Workshop, the form will POST to /workshops > (or PUT to /workshops/123 if editing a saved instance).[snip] Thanks a lot, James - makes perfect sense now. Jeff --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Hi.. I believe we are now prefixing the parent resource to the named route, so it will be workshop_sessions_path(@workshop, @sessions). -Shane On 6/6/07, James Adam <james.adam@gmail.com> wrote:> > 2. infer the named route method based on that object''s class, and > then pass the array as arguments to that array. So, what ends up being > called is > > sessions_path(@workshop, @session) > > which is the correct URL for this resource.-- http://shanesbrain.net --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Shane has it right. -- -Jonathan. On Jun 6, 12:56 pm, "Shane Vitarana" <sha...@gmail.com> wrote:> I believe we are now prefixing the parent resource to the named route, > so it will be workshop_sessions_path(@workshop, @sessions).--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Fixed another small bug, please apply the new patch... -- -Jonathan. --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Added unit tests and fixes for polymorphic_url. http://dev.rubyonrails.org/ticket/6432 -- -Jonathan. --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---