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.

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

#1688

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]

Reported by Mark Reginald James · January 2nd, 2009 @ 11:02 AM

State: wontfix
Milestone: 2.x
Assigned to: Pratik Pratik
Importance: none

Activity

  1. Mark Reginald James
    Mark Reginald James

    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?

    January 3rd, 2009 @ 03:52 AM

  2. Mark Reginald James
    Mark Reginald James
    • 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

    January 3rd, 2009 @ 03:54 AM

  3. Pratik
    Pratik
    • 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) %>
    

    March 8th, 2009 @ 12:29 AM

  4. Martin Schubert
    Martin Schubert

    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?

    January 7th, 2010 @ 10:55 PM