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.

render :layout does not work as per the documentation

#5893

If you pass arguments to “yield” then this will be passed to the block. One way to use this is to pass an array to layout and treat it as an enumerable.

<%# app/views/users/_user.html.erb &>
<div class="user">
  Budget: $<%= user.budget %>
  <%= yield user %>
</div>

<%# app/views/users/index.html.erb &>
<%= render :layout => @users do |user| %>
  Title: <%= user.title %>
<% end %>

This will render the layout for each user and yield to the block, passing the user, each time.

You can also yield multiple times in one layout and use block arguments to differentiate the sections.

<%# app/views/users/_user.html.erb &>
<div class="user">
  <%= yield user, :header %>
  Budget: $<%= user.budget %>
  <%= yield user, :footer %>
</div>

<%# app/views/users/index.html.erb &>
<%= render :layout => @users do |user, section| %>
  <%- case section when :header -%>
     Title: <%= user.title %>
  <%- when :footer -%>
    Deadline: <%= user.deadline %>
  <%- end -%>
<% end %>

I am trying out above scenarios on Rails 3.0.1 and it does not work. I get a error saying that no
block given.

Is the documentation missing something ??

Reported by pydi · October 30th, 2010 @ 01:44 AM

State: stale
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. Anil Wadghule
    Anil Wadghule

    If possible can you upload a demo rails app or possibly tests demoing above scenario. Thanks.

    October 30th, 2010 @ 07:19 AM

  2. pydi
    pydi

    I have created a test app in my git to reproduce this scenario

    http://github.com/pydi/test_partial

    Rendering <root_url>/users would show the error

    November 1st, 2010 @ 04:57 PM

  3. Santiago Pastorino
    Santiago Pastorino
    • State changed from new to open

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

    February 2nd, 2011 @ 04:21 PM

  4. Santiago Pastorino
    Santiago Pastorino
    • State changed from open to stale

    February 2nd, 2011 @ 04:21 PM