Posted by ant
August 8th, 2007
Filed in Rails
I submitted my first patch to Rails yesterday. I found that if you render a partial with a layout before you call yield in your site layout, the value that is returned by yield is whatever was rendered by your partial (without it’s layout) and not the rendered action as expected.
This is because the requested action is rendered before it’s layout, then stored in @content_for_layout (in the ActionView object). When render :partial => ‘blah’, :layout => ‘my_layout’ is called it stores it’s value in, you guessed it, @content_for_layout, thus overwriting the rendered action with the rendered partial. Thus, when you call yield from your site layout, the last partial rendered with layout (just the partial bit though) will always be returned.
The patch creates a copy of the current @content_for_layout before doing a render, then sets it back to its original value once the render has completed. It doesn’t seem to appear on the main ticket listing page though, I’m not sure why.
Blog uses Mephisto
Design from OSWD
by dreamLogic

Sorry, comments are closed for this article.