This project is archived and is in readonly mode.

#6148 ✓invalid
Jan

Parts of template are rendered twice, induced by yield or cache

Reported by Jan | December 11th, 2010 @ 12:29 PM

When I use a helper method, that yields to a given content block, the surrounding(!) template is rendered twice above where the helper is used. Rails 3.0.3.

Standard layout:

<!DOCTYPE html>
<html>
<head>
  <title>Foo</title>
  <%= stylesheet_link_tag :all %>
  <%= javascript_include_tag :defaults %>
  <%= csrf_meta_tag %>
</head>
<body>

<%= yield %>

</body>
</html>

Helper:

def foo(&block)
  yield
end

Template:

<p>TOP</p>

<%- foo do -%>
<p>YIELDED STUFF</p>
<%- end -%>

<p>BOTTOM</p>

Output:

TOP
YIELDED STUFF
TOP
YIELDED STUFF
BOTTOM

I'm having this same issue with cache do:

<p>TOP</p>

<%- if false; cache do -%>
Something
<%- end; else -%>
foobar
<%- end -%>

<p>BOTTOM</p>

Output:

TOP
foobar
TOP
foobar
BOTTOM

The double rendering does NOT occur like this:

<p>TOP</p>

<%- if false -%>
Something - without cache
<%- else -%>
foobar
<%- end -%>

<p>BOTTOM</p>

Or this:

<p>TOP</p>

<%- if true; cache do -%>
Something - note the TRUE in this version
<%- end; else -%>
Bar
<%- end -%>

<p>BOTTOM</p>

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Pages