This project is archived and is in readonly mode.

#5893 ✓stale
pydi

render :layout does not work as per the documentation

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

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 ??

Comments and changes to this ticket

  • Anil Wadghule

    Anil Wadghule October 30th, 2010 @ 07:19 AM

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

  • pydi

    pydi November 1st, 2010 @ 04:57 PM

    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

  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:21 PM

    • 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.

  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:21 PM

    • State changed from “open” to “stale”

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Pages