This project is archived and is in readonly mode.

#1896 ✓invalid
Stephen Blackstone

content_for not rendering from partials in layout

Reported by Stephen Blackstone | February 6th, 2009 @ 04:09 PM | in 2.x

I'm trying to bundle my javascsript and HTML together for - in this example - a YUI menu setup.


<head> <%= yield :head %> </head> <body> <%= render :partial => 'menu' %> <%= yield %> </body>

In my partial:

<% content_for :head do %> ** My Javascript for the menu ** <% end %> <br> My HTML for the menu..

It does not render into the block..

Comments and changes to this ticket

  • DHH

    DHH February 7th, 2009 @ 01:38 PM

    • State changed from “new” to “invalid”

    I just tried the same and cannot replicate that in 2.3 RC1. Please reopen if you still see the problem in 2.3. Including a failing test would help too.

  • Greg Hazel

    Greg Hazel July 20th, 2009 @ 03:38 AM

    I ran in to what I thought was this issue, but I was using fragment caching. Since the partial was not executed again, the content_for was not called.

    content_for could be written differently to handle this.

  • Greg Hazel

    Greg Hazel July 20th, 2009 @ 02:22 PM

    Also, this bug makes sense. The "yield :head" is executed before the "render :partial => 'menu'" is run, meaning it does not yet have content for :head.

    So, DHH, I don't believe you tried this, but I guess it's not a bug either.

  • Thomas Watson

    Thomas Watson August 10th, 2009 @ 11:16 AM

    Hmmm... I get this bug to in Rails 2.3.2.

    Ryan Bates did a RailsCast on this back in 2007. But now, suddenly a lot of comments are appearing on the episode page, discussing Rails 2.3.2 and that this now doesn't work:

    http://railscasts.com/episodes/8-layouts-and-content-for

  • maurizio.demagnis (at gmail)

    maurizio.demagnis (at gmail) November 13th, 2009 @ 12:25 PM

    • Tag set to content_for, partials, yield

    I'm experiencing the same problem: http://pastie.org/697104
    my environment:
    $ rails -v ruby -vRails 2.3.4
    $ ruby -v ruby 1.8.7 (2008-08-11 patchlevel 72) [universal-darwin10.0]
    $ uname -a Darwin MacBook-di-maurizio-de-magnis.local 10.0.0 Darwin Kernel Version 10.0.0: Fri Jul 31 22:47:34 PDT 2009; root:xnu-1456.1.25~1/RELEASE_I386 i386 i386

    That's pretty annoying imho :)

  • Matthew Daubert

    Matthew Daubert September 27th, 2010 @ 01:07 AM

    • Importance changed from “” to “”

    I'm experiencing the same problem on Rails 3.0.0

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>

Referenced by

Pages