<%= yield %> displays previous render's <%= yield %>

Hi all,

I’m trying to get a nested partial to display, but yield keeps
displaying the previous render’s yield.

I have a view:

<%=
render(
:partial => ‘user/edit_photo’,
:layout => ‘shared/edit’
)
%>

The partial’s layout:

<%= render( :partial => 'shared/edit/title', :layout => 'shared/pane', :locals => { :pane => View::Pane.new( 'pane-dark', :filled => View::Pane::FILLED ), :done_href => 'javascript:void(0);' } ) %>
<%= yield %>
...

When the page actually renders, the partial’s yield outputs ‘shared/
edit/title’. When I remove the rendering of ‘shared/edit/title’, the
yield correctly outputs ‘user/edit_photo’. Why? If you are wondering
why the view just renders a partial, it is because I have a layout
that wraps the view and wanted another layout that would do some more
wrapping.

I fixed it by first saving yield to a local

<% yield_output = yield %>

<% yield_output %>

Still wondering I couldn’t just do <%= yield %>

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs