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”
elsif (record.respond_to?(:persisted?) && !record.persisted?)
elsif record.is_a?(Class)

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.

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.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs