[Rails] Re: polymorphic_url
Oh, I figured this one out. Reason why the else doesn't pop the last
element is because the last element is the object passed to form_for
that has been persisted, and that element is needed in the array for
the id value when we invoke send on the dynamic route generated.
On Sep 3, 2:57 pm, John Merlino <stoici...@aol.com> wrote:
> In polymorphic_routes.rb, polymorphic_url is defined in rails source
> from github,and this particular line:
>
> inflection = if options[:action] && options[:action].to_s == "new"
> args.pop
> :singular
> elsif (record.respond_to?(:persisted?) && !record.persisted?)
> args.pop
> :plural
> elsif record.is_a?(Class)
> args.pop
> :plural
> else
> :singular
> end
>
> what's the purpose of extracting last element of array here? At this
> point args will either be an array of activerecord objects, or just be
> a single activerecord object in an array.
--
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@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home