mirror of https://github.com/rails/rails
Cached collections only work if there is one template
Cached collections only work if there is one template. If there are more than one templates, the caching mechanism doesn't have a key.
This commit is contained in:
parent
38f9e41f2c
commit
bfcdd46614
|
@ -308,6 +308,9 @@ module ActionView
|
|||
template = find_partial(@path, @template_keys)
|
||||
@variable ||= template.variable
|
||||
else
|
||||
if options[:cached]
|
||||
raise NotImplementedError, "render caching requires a template. Please specify a partial when rendering"
|
||||
end
|
||||
template = nil
|
||||
end
|
||||
|
||||
|
@ -337,9 +340,14 @@ module ActionView
|
|||
spacer = find_template(@options[:spacer_template], @locals.keys).render(view, @locals)
|
||||
end
|
||||
|
||||
cache_collection_render(payload, view, template) do
|
||||
template ? collection_with_template(view, template) : collection_without_template(view)
|
||||
end.join(spacer).html_safe
|
||||
collection_body = if template
|
||||
cache_collection_render(payload, view, template) do
|
||||
collection_with_template(view, template)
|
||||
end
|
||||
else
|
||||
collection_without_template(view)
|
||||
end
|
||||
collection_body.join(spacer).html_safe
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -752,6 +752,17 @@ class CachedCollectionViewRenderTest < ActiveSupport::TestCase
|
|||
@view.render(partial: "test/cached_customer", collection: [customer], cached: true)
|
||||
end
|
||||
|
||||
test "collection caching does not work on multi-partials" do
|
||||
a = Object.new
|
||||
b = Object.new
|
||||
def a.to_partial_path; "test/partial_iteration_1"; end
|
||||
def b.to_partial_path; "test/partial_iteration_2"; end
|
||||
|
||||
assert_raises(NotImplementedError) do
|
||||
@controller_view.render(partial: [a, b], cached: true)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def cache_key(*names, virtual_path)
|
||||
digest = ActionView::Digestor.digest name: virtual_path, finder: @view.lookup_context, dependencies: []
|
||||
|
|
Loading…
Reference in New Issue