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.

content_for not rendering from partials in layout

#1896

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..

Reported by Stephen Blackstone · February 6th, 2009 @ 04:09 PM

State: invalid
Milestone: 2.x
Assigned to: nobody
Importance: none

Activity

  1. DHH
    DHH
    • 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.

    February 7th, 2009 @ 01:38 PM

  2. Greg Hazel
    Greg Hazel

    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.

    July 20th, 2009 @ 03:38 AM

  3. Greg Hazel
    Greg Hazel

    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.

    July 20th, 2009 @ 02:22 PM

  4. Thomas Watson
    Thomas Watson

    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

    August 10th, 2009 @ 11:16 AM

  5. maurizio.demagnis (at gmail)
    maurizio.demagnis (at gmail)
    • 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 :)

    November 13th, 2009 @ 12:25 PM

  6. Matthew Daubert
    Matthew Daubert
    • Importance changed from to

    I'm experiencing the same problem on Rails 3.0.0

    September 27th, 2010 @ 01:07 AM