Skip to content
This repository
Browse code

Documentation fixes for rendering partials

  • Loading branch information...
commit 2beea3b249763edcb133c1b7078958ef14815812 1 parent b65bd01
Olek Janiszewski exviva authored

Showing 1 changed file with 11 additions and 20 deletions. Show diff stats Hide diff stats

  1. +11 20 actionpack/lib/action_view/renderer/partial_renderer.rb
31 actionpack/lib/action_view/renderer/partial_renderer.rb
@@ -12,8 +12,7 @@ module ActionView
12 12 #
13 13 # <%= render :partial => "account" %>
14 14 #
15   - # This would render "advertiser/_account.html.erb" and pass the instance variable @account in as a local variable
16   - # +account+ to the template for display.
  15 + # This would render "advertiser/_account.html.erb".
17 16 #
18 17 # In another template for Advertiser#buy, we could have:
19 18 #
@@ -28,32 +27,24 @@ module ActionView
28 27 #
29 28 # == The :as and :object options
30 29 #
31   - # By default <tt>ActionView::Partials::PartialRenderer</tt> has its object in a local variable with the same
32   - # name as the template. So, given
  30 + # By default <tt>ActionView::Partials::PartialRenderer</tt> doesn't have any local variables.
  31 + # The <tt>:object</tt> option can be used to pass an object to the partial. For instance:
33 32 #
34   - # <%= render :partial => "contract" %>
  33 + # <%= render :partial => "account", :object => @buyer %>
35 34 #
36   - # within contract we'll get <tt>@contract</tt> in the local variable +contract+, as if we had written
  35 + # would provide the +@buyer+ object to the partial, available under the local variable +account+ and is
  36 + # equivalent to:
37 37 #
38   - # <%= render :partial => "contract", :locals => { :contract => @contract } %>
  38 + # <%= render :partial => "account", :locals => { :account => @buyer } %>
39 39 #
40 40 # With the <tt>:as</tt> option we can specify a different name for said local variable. For example, if we
41   - # wanted it to be +agreement+ instead of +contract+ we'd do:
42   - #
43   - # <%= render :partial => "contract", :as => 'agreement' %>
44   - #
45   - # The <tt>:object</tt> option can be used to directly specify which object is rendered into the partial;
46   - # useful when the template's object is elsewhere, in a different ivar or in a local variable for instance.
  41 + # wanted it to be +user+ instead of +account+ we'd do:
47 42 #
48   - # Revisiting a previous example we could have written this code:
  43 + # <%= render :partial => "account", :object => @buyer, :as => 'user' %>
49 44 #
50   - # <%= render :partial => "account", :object => @buyer %>
51   - #
52   - # <% @advertisements.each do |ad| %>
53   - # <%= render :partial => "ad", :object => ad %>
54   - # <% end %>
  45 + # This is equivalent to
55 46 #
56   - # The <tt>:object</tt> and <tt>:as</tt> options can be used together.
  47 + # <%= render :partial => "account", :locals => { :user => @buyer } %>
57 48 #
58 49 # == Rendering a collection of partials
59 50 #

0 comments on commit 2beea3b

Please sign in to comment.
Something went wrong with that request. Please try again.