This project is archived and is in readonly mode.

#1688 ✓wontfix
Mark Reginald James

Layout option for partial collections specifies an overall layout rather than a partial layout

Reported by Mark Reginald James | January 2nd, 2009 @ 11:02 AM | in 2.x

Say file _item.html.erb contains


<%= item %>

and file _bracket.html.erb contains


[<%= yield %>]

then


<%= render :partial => 'item', :layout => 'bracket', :collection => %w(a b) %>

should render


[a][b]

but instead renders


[ab][ab]

Comments and changes to this ticket

  • Mark Reginald James

    Mark Reginald James January 3rd, 2009 @ 03:52 AM

    The duplication is fixed in the current master, but render always looks for and treats the provided layout as a layout for the entire collection.

    I think being able to use a partial layout when rendering collections is more valuable than an overall layout.

    There are four alternatives:

    1. Leave as is.
    2. Make the layout option work as a partial layout instead.
    3. Allow automatic switching between the two modes depending on whether the target layout file starts with an underscore.
    4. Add a new :partial_layout option to render.

    Which is preferred?

  • Mark Reginald James

    Mark Reginald James January 3rd, 2009 @ 03:54 AM

    • Title changed from “Layout option does not work when rendering partial collections” to “Layout option for partial collections specifies an overall layout rather than a partial layout”
  • Pratik

    Pratik March 8th, 2009 @ 12:29 AM

    • Assigned user set to “Pratik”
    • State changed from “new” to “wontfix”

    You should just use the layout inside the partial :

    
    # _brackets.html.erb
    [<%= yield %>]
    
    # _item.html.erb
    <% render(:layout => 'bracket) do %>
    <%= item %>
    <% end %>
    
    # collection.html.erb
    <%= render :partial => 'item', :collection => %w(a b) %>
    
  • Martin Schubert

    Martin Schubert January 7th, 2010 @ 10:55 PM

    Even the ticket is allready a year old i keep to stumble into the same situation:

    needing different layouts for each item when a collection is rendered.

    the solution from "Pratik" doesnt solve this problem.

    or is there another workaround i am not aware of?

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>

Pages