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.

Added a :style option for rendering partials with RecordIdentifier

#1646

Added a :style option for rendering partials with RecordIdentifier, allowing the same object to be rendered with a different partial to suit different rendering situations.

The value of :style is used to add a suffix to the standard partial name provided by RecordIdentifier#partial_path. Examples:

# Before:
<%= render :partial => "posts/post_summary", :locals => { :post => @post } %> 
# After:
<%= render :partial => @post, :style => :summary %>

# Before:
<%= render :partial => "posts/post_summary", :collection => @posts, :as => :post %> 
# After:
<%= render :partial => @posts, :style => :summary %> 

This also heavily reduces the noisy view code if you want to use an alternate partial on a collection of objects with differing classes, like records from a table with STI.

Reported by Justin French · December 27th, 2008 @ 01:21 PM

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

Activity

  1. DHH
    DHH
    • State changed from new to wontfix

    I would almost think that the latest improvement to render would make this unneeded. See http://github.com/rails/rails/co...

    You'd do your example as: <%= render("post_summary", :post => @post) %>. That seems just as long and doesn't require a special exception for :style.

    December 27th, 2008 @ 01:39 PM

  2. Justin French
    Justin French

    For the record, have been discussing this elsewhere. DHH's solution only solves one of the cases (not the collection version), but we're coming up with a plan B. Will leave this in wontfix.

    December 27th, 2008 @ 01:55 PM