This project is archived and is in readonly mode.
Rails 3.0 yield :name doesn't show content_for :name
-
Jeff Kreeftmeijer
I was unable to reproduce it on master with this setup:
application.html.erb:
<%= render('some_partial') %>users/_some_partial.html.erb:
<%= yield(:script) %>users/index.html.erb:
<% content_for(:script) { 'works!' } %>Can anyone else? I'll try to reproduce your exact example later, but I don't think it will make a difference. :)
-
Matthew Daubert
Thank you Jeff - Your example works for me, too. I think the problem may be specifically with calling content_for from within a partial and yielding in a different partial. I couldn't find anything in RDoc => CaptureHelper that would indicate that this shouldn't work and I thought it was working in 2.3.9. I'll upload a failing app as soon as I get a few minutes. :)
-
Matthew Daubert
Attached is a barebones app that fails for me (Rails 3.0.0, Ruby 1.9.2p0 x86_64-darwin10.4.0, OSX 10.6.4). The partial shared/messages has content_for(:script) but no content is rendered from the layout's yield(:script) statement.
-
Luca Guidi
IMO this isn't a bug, because AV renders the template first then the layout.
In your example:
1. The template is being rendered (mainyield)
2. AV starts with the layout
2a. It rendersshared/head, at this timecontent_for(:script)wasn't triggered yet, that's becauseyielddoesn't print anything
2b. It rendersshared/messages, now the content are initialized but the above partial was already rendered. -
Ryan Bigg
- State changed from new to wontfix
- Importance changed from to Low
Luca is correct.
If the
yield :blahis processed before thecontent_for :blahthen theyieldwill output nothing. -
Ryan Bigg
- Tag changed from rails3.0.0 to 3.0.0
