From ae75930b59e7b41133c5a62c09da3c02309f81f3 Mon Sep 17 00:00:00 2001 From: Steven Harman Date: Thu, 21 Jul 2016 13:15:59 -0400 Subject: Fix collection_from_options to allow Enumerators An optimization was introduced in https://github.com/rails/rails/commit/27f4ffd11a91b534fde9b484cb7c4e515ec0fe77 which tried to `#to_ary` the collection to prevent unnecessary queries for ActiveRecord scopes/relations. If the given collection did not respond to `#to_ary`, and empty collection was returned. That meant you couldn't use collections built from `Enumerator` nor `Enumerable`. With this change, `#collection_from_options` will attempt the optimization, but fall back to passing along the given collection, as-is. --- actionview/lib/action_view/renderer/partial_renderer.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'actionview/lib/action_view/renderer') diff --git a/actionview/lib/action_view/renderer/partial_renderer.rb b/actionview/lib/action_view/renderer/partial_renderer.rb index c2b15e72e9..1b28c180e3 100644 --- a/actionview/lib/action_view/renderer/partial_renderer.rb +++ b/actionview/lib/action_view/renderer/partial_renderer.rb @@ -404,7 +404,8 @@ module ActionView def collection_from_options if @options.key?(:collection) collection = @options[:collection] - collection.respond_to?(:to_ary) ? collection.to_ary : [] + collection = collection.to_ary if collection.respond_to?(:to_ary) + collection end end -- cgit v1.2.3