diff options
author | Santiago Pastorino <santiago@wyeworks.com> | 2016-07-26 14:14:41 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-07-26 14:14:41 -0300 |
commit | 49315e278944b65f2ffd1c95caf342b17a692327 (patch) | |
tree | 1567f23bc5fea4fe6c483d768661f6d86566d3c8 /actionview | |
parent | c4b33a779680ee8f38d510789dfe1b3749a47734 (diff) | |
parent | 87899cfcf0ada140764acf4393eb862698449f54 (diff) | |
download | rails-49315e278944b65f2ffd1c95caf342b17a692327.tar.gz rails-49315e278944b65f2ffd1c95caf342b17a692327.tar.bz2 rails-49315e278944b65f2ffd1c95caf342b17a692327.zip |
Merge pull request #25912 from stevenharman/fix_render_partial_collection_to_allow_custom_collection
Changed partial rendering to allow collections which don't implement `#to_ary`.
Diffstat (limited to 'actionview')
-rw-r--r-- | actionview/CHANGELOG.md | 11 | ||||
-rw-r--r-- | actionview/lib/action_view/renderer/partial_renderer.rb | 2 | ||||
-rw-r--r-- | actionview/test/template/render_test.rb | 8 |
3 files changed, 20 insertions, 1 deletions
diff --git a/actionview/CHANGELOG.md b/actionview/CHANGELOG.md index ab4b46c56e..7754bd8dd9 100644 --- a/actionview/CHANGELOG.md +++ b/actionview/CHANGELOG.md @@ -1,3 +1,14 @@ +* Changed partial rendering with a collection to allow collections which + implement `to_a`. + + 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`. By changing this to + `#to_a`, they will now be extracted and rendered as expected. + + *Steven Harman* + * New syntax for tag helpers. Avoid positional parameters and support HTML5 by default. Example usage of tag helpers before: diff --git a/actionview/lib/action_view/renderer/partial_renderer.rb b/actionview/lib/action_view/renderer/partial_renderer.rb index c2b15e72e9..7c2e07185c 100644 --- a/actionview/lib/action_view/renderer/partial_renderer.rb +++ b/actionview/lib/action_view/renderer/partial_renderer.rb @@ -404,7 +404,7 @@ module ActionView def collection_from_options if @options.key?(:collection) collection = @options[:collection] - collection.respond_to?(:to_ary) ? collection.to_ary : [] + collection ? collection.to_a : [] end end diff --git a/actionview/test/template/render_test.rb b/actionview/test/template/render_test.rb index 25b21850b1..68574d4adb 100644 --- a/actionview/test/template/render_test.rb +++ b/actionview/test/template/render_test.rb @@ -309,6 +309,14 @@ module RenderTestCases assert_nil @view.render(:partial => "test/customer", :collection => nil) end + def test_render_partial_collection_for_non_array + customers = Enumerator.new do |y| + y.yield(Customer.new("david")) + y.yield(Customer.new("mary")) + end + assert_equal "Hello: davidHello: mary", @view.render(partial: "test/customer", collection: customers) + end + def test_render_partial_without_object_does_not_put_partial_name_to_local_assigns assert_equal 'false', @view.render(partial: 'test/partial_name_in_local_assigns') end |