Monday, September 3, 2012

[Rails] RoutesProxy

when passing an array as first argument to form_for, polymorphic_url
checks if first index is an instance of
ActionDispatch::Routing::RoutesProxy:

def polymorphic_url(record_or_hash_or_array, options = {})
if record_or_hash_or_array.kind_of?(Array)
record_or_hash_or_array = record_or_hash_or_array.compact
if record_or_hash_or_array.first.is_a?
(ActionDispatch::Routing::RoutesProxy)
proxy = record_or_hash_or_array.shift
end
record_or_hash_or_array = record_or_hash_or_array[0] if
record_or_hash_or_array.size == 1
end
...

It later than calls a named route on routesproxy object if it is not
nil:

(proxy || self).send(named_route, *args)

What exactly is RoutesProxy?

The documentation does a terrible job at explaining it:

http://rubydoc.info/docs/rails/ActionDispatch/Routing/RoutesProxy

And at moment I'd prefer some feedback before digging into the source.

--
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


Real Estate