mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Use to_a to pre-buffer the collection
We can safely assume we're not dealing with an infinite collection as we're about to call `each` on it and collect the results until it terminates on its own. Given that, `to_a` is implemented by the normal Array-like objects, and less Array-like objects like `Enumerator` and `Enumerator::Lazy`.
This commit is contained in:
parent
e4a4936244
commit
87899cfcf0
2 changed files with 7 additions and 8 deletions
|
@ -1,11 +1,11 @@
|
|||
* Changed partial rendering with a collection to allow collections which
|
||||
don't implement `to_ary`.
|
||||
implement `to_a`.
|
||||
|
||||
Extracting the collection option has an optimization to avoid unnecessary
|
||||
queries of ActiveRecord Relations by calling `to_ary` on the given
|
||||
Extracting the collection option had an optimization to avoid unnecessary
|
||||
queries of ActiveRecord Relations by calling `#to_ary` on the given
|
||||
collection. Instances of `Enumerator` or `Enumerable` are valid
|
||||
collections, but they do not implement `#to_ary`. They will now be
|
||||
extracted and rendered as expected.
|
||||
collections, but they do not implement `#to_ary`. By changing this to
|
||||
`#to_a`, they will now be extracted and rendered as expected.
|
||||
|
||||
*Steven Harman*
|
||||
|
||||
|
|
|
@ -403,9 +403,8 @@ module ActionView
|
|||
|
||||
def collection_from_options
|
||||
if @options.key?(:collection)
|
||||
collection = @options[:collection] || []
|
||||
collection = collection.to_ary if collection.respond_to?(:to_ary)
|
||||
collection
|
||||
collection = @options[:collection]
|
||||
collection ? collection.to_a : []
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue