# Polymorphic\_url

**URL:** <https://www.ruby-forum.com/t/polymorphic-url/222607>\
**Category:** Rails\
**Created:** [September 3, 2012, 8:58pm UTC](https://www.ruby-forum.com/t/polymorphic-url/222607 "2012-09-03T20:58:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [September 3, 2012, 8:58pm UTC](https://www.ruby-forum.com/t/polymorphic-url/222607/1 "2012-09-03T20:58:12Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jmaenpaa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de053/32.png) [@jmaenpaa](https://www.ruby-forum.com/u/jmaenpaa)\
**Post date:** [September 4, 2012, 6:43am UTC](https://www.ruby-forum.com/t/polymorphic-url/222607/2 "2012-09-04T06:43:37Z")

</div>

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.
