I have a partial that has a couple of content_for blocks in it. This
works fine if I render it from a view that will in itself get rendered
view yield :layout. But, if I try and render it directly from the
application layout none of the content_for stuff gets interpreted.
Two questions
Is this right?
If so, how can I always include a partial inside of my views then?
I have a similar problem. Upgrading to Rails 2.2.2 from 2.1.2 i’ve
lost all view components that are inserted with content_for.
The content_for call sits inside a view helper, which in turn is used
inside the view (eg #30 Pretty Page Title - RailsCasts).
If i move the content_for call to inside the view it works fine.
And it is not rendering the content into my header thats defined in the
partial thats rendered in the layout. I’m using some of the YUI stuff
and
I’m bundling the javascript and the html in the same file so it stays
together nice and neat.
The problem you’ve run into is that yield blocks have to be filled
before they are called - normally,
with the yields in the layout, everything else from the request will
render first. But since you’re calling
content_for in the layout, things aren’t working.
The quickest way to do what you’re trying would be to put the html
part in a content_for block, and then
call the partial from the header (with a yield :menu_body where the
current partial is). That puts the blocks
into the correct order.
–Matt J.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.