This project is archived and is in readonly mode.

#2279 ✓stale
Jeff Schuil

render :layout with block and multiple yields renders twice

Reported by Jeff Schuil | March 17th, 2009 @ 10:12 PM | in 2.3.10

Its possible I'm misusing render :layout for sharing view markup between layouts, but this seems strange nonetheless.


<!-- layouts/_common.html.erb -->
common
<%= yield :top %>
<%= yield %>

<!-- layouts/application.html.erb -->
<% render :layout => 'layouts/common' do %>
  layout
  <%= yield :layout %>
<% end %>

<!-- some view -->
view

outputs (newlines added):

common
layout   <-- Added by yield :top
view
layout   <-- Added by yield
view

Notice, I haven't declared content_for :top, but it is outputting an extra 'layout view'.

Adding any yields to common with an argument, like 'yield :bottom', also output the extra 'layout view'.

Note: In application.html.erb, I tried just putting yield, not yield :layout, but I got a stack level too deep error.

I reworked my shared layouts to not pass a block to render :layout, but thought I would see if this was in fact a bug.

Comments and changes to this ticket

  • Jeff Schuil

    Jeff Schuil March 17th, 2009 @ 10:35 PM

    Also, in _common.html.erb, if instead of <%= yield :top %> I use (the deprecated) <%= @content_for_top %> it works as expected.

  • Steve Madsen

    Steve Madsen December 16th, 2009 @ 03:03 AM

    • Tag changed from content_for, layout, render, yield to 2.3.5, content_for, layout, render, yield

    I don't see a doubled "view", but I can confirm that I reproduced the "stack too deep" problem when rendering a complex template on 2.3.5. In my case, the template rendered a block with a layout, and inside the block, rendered a partial with a different layout, the whole thing wrapped in a normal layout. Yes, hairy. Inherited code, one of many things I'm trying to clean up.

    Specifying "yield :layout" explicitly in every template that acts as a layout fixed the recursion that happens due to the render-block-with-layout code. The problem also goes away if I remove the render-block-with-layout (keeping the inner part), though in that case part of the page design goes away, so it's not a very good fix.

  • Leandro Pedroni

    Leandro Pedroni February 3rd, 2010 @ 03:38 PM

    There's also a problem with passing a layout to render a collection with partials.
    The layout is applied around the whole collection (as expected), but the whole thing (layout plus collection partials) gets rendered as many times as the items in the collection.

    Here's a quick patch that should fix both problems...

  • Rasmus Rønn Nielsen

    Rasmus Rønn Nielsen February 23rd, 2010 @ 09:38 AM

    I've run into this problem running ruby1.9.1 and rails 3 beta. I'm trying to use two "render :layout do [something] end" inside each other.

  • Jeremy Kemper

    Jeremy Kemper May 4th, 2010 @ 06:48 PM

    • Milestone changed from 2.x to 3.x
  • Aditya

    Aditya June 27th, 2010 @ 08:55 PM

    • Importance changed from “” to “”

    Confirm that this is a problem on 2.3.8 as well.

    Leandro's patch fixes the problem of repeated output when passing collection is used problem.
    Render layout with block however is not working (with or without the patch above).

    Ruby -v
    ruby 1.8.7 (2010-06-07 patchlevel 268)

  • Santiago Pastorino

    Santiago Pastorino June 30th, 2010 @ 01:59 AM

    • Tag changed from 2.3.5, content_for, layout, render, yield to content_for, layout, render, yield
    • Assigned user set to “Santiago Pastorino”
    • State changed from “new” to “open”
    • Milestone cleared.
    • Importance changed from “” to “Medium”

    Leandro can you provide a patch following http://rails.lighthouseapp.com/projects/8994/sending-patches and add a test for this cases?.
    Thank you.

  • Neeraj Singh

    Neeraj Singh July 1st, 2010 @ 03:44 AM

    I am not able to reproduce this problem in 2-3-stable. However Aditya was able to recreate this problem just 3 days ago. Not sure what's going on.

    Can someone else try?

  • masone

    masone July 18th, 2010 @ 12:06 PM

    I can reproduce the output described by Jeff with Rails 2.3.8, Ruby 1.8.7 and 1.9.2.

  • Santiago Pastorino

    Santiago Pastorino July 19th, 2010 @ 04:37 PM

    Is this an issue on master too? or only 2-3-stable?

  • Rohit Arondekar

    Rohit Arondekar August 3rd, 2010 @ 08:41 AM

    • Milestone set to 2.3.9

    I can't reproduce this on 3-0-stable. Changing milestone.

    Can somebody please try this in 2-3-stable?

  • Santiago Pastorino

    Santiago Pastorino August 3rd, 2010 @ 04:42 PM

    masone has reproduced this on 2.3.8 on July 18th, can you try it on 2-3-stable from git?.
    And can someone provide a patch

  • Jeremy Kemper

    Jeremy Kemper August 30th, 2010 @ 02:28 AM

    • Milestone changed from 2.3.9 to 2.3.10
  • jgeiger

    jgeiger September 27th, 2010 @ 06:51 PM

    I've created a sample app that may or may not be this issue but is very similar. I'm not sure that the yields are causing the failures.

    http://github.com/jgeiger/double_render_bug

  • Shimon Young

    Shimon Young October 6th, 2010 @ 11:08 AM

    Isn't this because actionpack-3.0.0\lib\action_view\render\rendering.rb is:

    def render(options = {}, locals = {}, &block)
      case options
      when Hash
        if block_given?
          _render_partial(options.merge(:partial => options[:layout]), &block)
    

    where it should be?

    def render(options = {}, locals = {}, &block)
      case options
      when Hash
        if block_given?
          options.merge!(:partial => options[:layout])
          options.delete(:layout)
          _render_partial(options, &block)
    
  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:58 PM

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:58 PM

    • State changed from “open” to “stale”

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>

Attachments

Pages