mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
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`.
This commit is contained in:
parent
e2f749dc2b
commit
61d4d738e1
3 changed files with 20 additions and 1 deletions
|
@ -1,5 +1,16 @@
|
|||
## Rails 5.0.0 (June 30, 2016) ##
|
||||
|
||||
* 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*
|
||||
|
||||
* Change `datetime_field` and `datetime_field_tag` to generate `datetime-local` fields.
|
||||
|
||||
As a new specification of the HTML 5 the text field type `datetime` will no longer exist
|
||||
|
|
|
@ -403,7 +403,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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue