It's really frustrating to see how much stuff is being bolted on here. I've already written at length about how edge-cases (poly* resources) are being allowed to infect simpler cases:
http://rubyurl.com/jzN And with this suggestion it just keeps getting worse. By far the simplest and most common case is this: form_for @something do ... end That's easy. You haven't told form_for what the url is so it will best-guess it using @something.class and @something.new_record? That doesn't work for you because you're doing something unusual with name_prefix or you've got a deeply nested resource? Sucks to be you for doing something complicated: form_for @something, :url => polymorphic_path(@parent, @of, @something, :namespace => :something_arbitrary) do ... end form_for *already* has a facility to supply a url that overrides any guesswork. And did you see how polymorphic_path can have a richer interface? Trying to ram a rich set of arguments down the throat of form_for by wrapping stuff up in an array is just plain ugly. Take a look at this: url_for([EMAIL PROTECTED], @child]) You know you want polymorphic_url to be called so you wrap up your arguments into an array so that they'll get passed through. Then polymorphic_url tries to guess the url helper to be invoked. It builds a string based on the class of each argument because the auto-name_prefix convention demands it (otherwise it could just use the class of @child). Then polymorphic_url calls the parent_child_url() helper, passing the arguments through. parent_child_helper() unpacks the arguments into a single options hash and then calls... wait for it .... url_for(). Compare the two: url_for([EMAIL PROTECTED], @child]) polymorphic_url(@parent, @child) Seriously, what's clearer and easier to explain to a newcomer? Save us all and stop trying to tunnel arguments to polymorphic_xxx through the method signature of url_for and form_for. Trevor On 6/8/07, Tobias Lütke <[EMAIL PROTECTED]> wrote: > > I'd apply a patch which would Dan's style work. > > Please do investigate :) > > > > > # routes.rb > > map.namespace :admin do |a| > > a.resources :workshops do |w| > > w.resources :sessions > > end > > end > > > > # views > > <%= url_for([:admin, @workshop, @session]) %> > > <%= link_to('Session', [:admin, @workshop, @session]) %> > > <% form_for([:admin, @workshop, @session] do |f| %> > > # ... > > <% end %> > > > > The symbol would correspond to the namespace, and could be made to > > handle nested namespaces. > > > -- > Tobi > http://shopify.com - modern e-commerce software > http://typo.leetsoft.com - Open source weblog engine > http://blog.leetsoft.com - Technical weblog > > > > -- -- Trevor Squires http://somethinglearned.com --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
