mirror of https://github.com/rails/rails
Fix rendering a differently-formatted partial after caching
This commit is contained in:
parent
998da3cb34
commit
4f99a21864
|
@ -173,6 +173,9 @@ class FunctionalCachingController < CachingController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def xml_fragment_cached_with_html_partial
|
||||||
|
end
|
||||||
|
|
||||||
def formatted_fragment_cached
|
def formatted_fragment_cached
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html
|
format.html
|
||||||
|
@ -308,6 +311,11 @@ CACHED
|
||||||
@store.read("views/functional_caching/formatted_fragment_cached_with_variant:#{template_digest("functional_caching/formatted_fragment_cached_with_variant")}/fragment")
|
@store.read("views/functional_caching/formatted_fragment_cached_with_variant:#{template_digest("functional_caching/formatted_fragment_cached_with_variant")}/fragment")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_fragment_caching_with_html_partials_in_xml
|
||||||
|
get :xml_fragment_cached_with_html_partial, format: "*/*"
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def template_digest(name)
|
def template_digest(name)
|
||||||
ActionView::Digestor.digest(name: name, finder: @controller.lookup_context)
|
ActionView::Digestor.digest(name: name, finder: @controller.lookup_context)
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
<p>Hello!</p>
|
|
@ -0,0 +1,5 @@
|
||||||
|
cache do
|
||||||
|
xml.title "Hello!"
|
||||||
|
end
|
||||||
|
|
||||||
|
xml.body cdata_section(render("formatted_partial"))
|
|
@ -45,9 +45,8 @@ module ActionView
|
||||||
# Create a dependency tree for template named +name+.
|
# Create a dependency tree for template named +name+.
|
||||||
def tree(name, finder, partial = false, seen = {})
|
def tree(name, finder, partial = false, seen = {})
|
||||||
logical_name = name.gsub(%r|/_|, "/")
|
logical_name = name.gsub(%r|/_|, "/")
|
||||||
finder.formats = [finder.rendered_format] if finder.rendered_format
|
|
||||||
|
|
||||||
if template = finder.disable_cache { finder.find_all(logical_name, [], partial, []).first }
|
if template = find_template(finder, logical_name, [], partial, [])
|
||||||
finder.rendered_format ||= template.formats.first
|
finder.rendered_format ||= template.formats.first
|
||||||
|
|
||||||
if node = seen[template.identifier] # handle cycles in the tree
|
if node = seen[template.identifier] # handle cycles in the tree
|
||||||
|
@ -69,6 +68,17 @@ module ActionView
|
||||||
seen[name] ||= Missing.new(name, logical_name, nil)
|
seen[name] ||= Missing.new(name, logical_name, nil)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def find_template(finder, *args)
|
||||||
|
finder.disable_cache do
|
||||||
|
if format = finder.rendered_format
|
||||||
|
finder.find_all(*args, formats: [format]).first || finder.find_all(*args).first
|
||||||
|
else
|
||||||
|
finder.find_all(*args).first
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class Node
|
class Node
|
||||||
|
|
Loading…
Reference in New Issue