Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Rails 3.0.0, 'yield' won't show block contents in render :layout, if it is placed after render :partial

#5557

After migrating to Rails 3.0.0, following code doesn't work correctly anymore:

# app/views/layouts/_example_layout.html.erb
Before
<%= render :partial => "/example_partial.html.erb" %>
<%= yield %>
After

# app/views/_example_partial.html.erb
<%= "It is partial" %>

# app/views/example/index.html.erb
<%= render :layout => "/layouts/example_layout" do %>
  <%= "Block's content" %>
<% end %>

It will display:

Before
It is partial
After

instead of:

Before
It is partial
Block content
After

Looks like the reason of the issue is reusing of the PartialRenderer object in ActionView::Partials#_render_partial method and setting up empty block of render :partial (instead of real block of render :layout) to it.

Test for the issue is attached.

Reported by Anton Astashov · September 5th, 2010 @ 03:03 PM

State: resolved
Milestone: 3.0.5
Assigned to: Santiago Pastorino Santiago Pastorino
Importance: Low

Activity

  1. Marjan Krekoten'
    Marjan Krekoten'
    • Assigned user set to Santiago Pastorino
    • Tag changed from block, layout, partial, render to block, layout, partial, patch, render

    Fix attached. Also contains test case from Anton Astashov.

    September 5th, 2010 @ 05:13 PM

  2. David Trasbo
    David Trasbo

    +1

    Patch applies cleanly and the included test fails without the fix but passes with it.

    September 5th, 2010 @ 06:54 PM

  3. José Valim
    José Valim
    • Milestone set to 3.x
    • State changed from new to open
    • Assigned user changed from Santiago Pastorino to Yehuda Katz (wycats)
    • Importance changed from to Low

    Unfortunately this fix hits performance. Do we have other options?

    September 5th, 2010 @ 07:42 PM

  4. Anton Astashov
    Anton Astashov

    Maybe we can pass a block right to ActionView::Partials::PartialRenderer#render instead of passing it to initialize/setup methods? Please take a look at the attached path.

    September 6th, 2010 @ 02:22 AM

  5. bfalling
    bfalling

    +1

    I don't know how others are working around this, but this bug has bitten us in a number of apps.

    Thanks!

    November 25th, 2010 @ 05:11 AM

  6. Tyler McGill
    Tyler McGill

    This just killed 5 hours of development time for me. I'm glad I found this bug report. I'm using 3.0.3. Any update on status?

    January 24th, 2011 @ 03:33 AM

  7. Santiago Pastorino
    Santiago Pastorino
    • Milestone cleared.
    • Assigned user changed from Yehuda Katz (wycats) to Santiago Pastorino

    Anton, the patch looks good to me. I'm going to apply it, but doesn't apply cleanly now :'(.
    Can you rebase it to master and 3-0-stable?. Thanks.

    January 31st, 2011 @ 09:33 PM

  8. Santiago Pastorino
    Santiago Pastorino

    Guys the release is going to happen tomorrow please send a rebased patch :).

    February 2nd, 2011 @ 08:03 PM

  9. Anton Astashov
    Anton Astashov

    Good news - I've applied tests from the patch to 'master' and '3-0-stable' (only the tests, not the actual code), and they passed, all tests are passed. Also, tried to create demo rails app and check this issue there - it works fine. So, looks like the ticket can be closed - this issue was fixed already. Hooray! :)

    February 3rd, 2011 @ 02:39 AM

  10. Santiago Pastorino
    Santiago Pastorino

    Anton cool, so can you provide a patch with only tests so we can be sure to avoid a regression?

    February 3rd, 2011 @ 11:55 AM

  11. Anton Astashov
  12. Anton Astashov
  13. Repository
    Repository
    • State changed from open to resolved

    (from [c1c6f29214d3c280f5d1d4abb49d0b90424fcbd7]) Add a test for 'render :layout'

    To make sure it will show block contents if it is placed after 'render
    :partial'

    [#5557 Rails 3.0.0, 'yield' won't show block contents in render :layout, if it is pl... state:resolved]

    Signed-off-by: Santiago Pastorino santiago@wyeworks.com
    https://github.com/rails/rails/commit/c1c6f29214d3c280f5d1d4abb49d0...

    February 3rd, 2011 @ 02:58 PM

  14. Repository
    Repository

    (from [53b0235282ebb4953ef2e0644e64c232ec902ef2]) Add a test for 'render :layout'

    To make sure it will show block contents if it is placed after 'render
    :partial'

    [#5557 Rails 3.0.0, 'yield' won't show block contents in render :layout, if it is pl... state:resolved]

    Signed-off-by: Santiago Pastorino santiago@wyeworks.com
    https://github.com/rails/rails/commit/53b0235282ebb4953ef2e0644e64c...

    February 3rd, 2011 @ 03:11 PM

  15. Santiago Pastorino