--- !ruby/object:RI::ClassDescription 
attributes: []

class_methods: []

comment: 
- !ruby/struct:SM::Flow::P 
  body: There's also a convenience method for rendering sub templates within the current controller that depends on a single object (we call this kind of sub templates for partials). It relies on the fact that partials should follow the naming convention of being prefixed with an underscore -- as to separate them from regular templates that could be rendered on their own.
- !ruby/struct:SM::Flow::P 
  body: "In a template for Advertiser#account:"
- !ruby/struct:SM::Flow::VERB 
  body: " &lt;%= render :partial =&gt; &quot;account&quot; %&gt;\n"
- !ruby/struct:SM::Flow::P 
  body: This would render &quot;advertiser/_account.erb&quot; and pass the instance variable @account in as a local variable <tt>account</tt> to the template for display.
- !ruby/struct:SM::Flow::P 
  body: "In another template for Advertiser#buy, we could have:"
- !ruby/struct:SM::Flow::VERB 
  body: "  &lt;%= render :partial =&gt; &quot;account&quot;, :locals =&gt; { :account =&gt; @buyer } %&gt;\n\n  &lt;% for ad in @advertisements %&gt;\n    &lt;%= render :partial =&gt; &quot;ad&quot;, :locals =&gt; { :ad =&gt; ad } %&gt;\n  &lt;% end %&gt;\n"
- !ruby/struct:SM::Flow::P 
  body: This would first render &quot;advertiser/_account.erb&quot; with @buyer passed in as the local variable <tt>account</tt>, then render &quot;advertiser/_ad.erb&quot; and pass the local variable <tt>ad</tt> to the template for display.
- !ruby/struct:SM::Flow::H 
  level: 2
  text: Rendering a collection of partials
- !ruby/struct:SM::Flow::P 
  body: "The example of partial use describes a familiar pattern where a template needs to iterate over an array and render a sub template for each of the elements. This pattern has been implemented as a single method that accepts an array and renders a partial by the same name as the elements contained within. So the three-lined example in &quot;Using partials&quot; can be rewritten with a single line:"
- !ruby/struct:SM::Flow::VERB 
  body: "  &lt;%= render :partial =&gt; &quot;ad&quot;, :collection =&gt; @advertisements %&gt;\n"
- !ruby/struct:SM::Flow::P 
  body: This will render &quot;advertiser/_ad.erb&quot; and pass the local variable <tt>ad</tt> to the template for display. An iteration counter will automatically be made available to the template with a name of the form <tt>partial_name_counter</tt>. In the case of the example above, the template would be fed <tt>ad_counter</tt>.
- !ruby/struct:SM::Flow::P 
  body: "NOTE: Due to backwards compatibility concerns, the collection can't be one of hashes. Normally you'd also just keep domain objects, like Active Records, in there."
- !ruby/struct:SM::Flow::H 
  level: 2
  text: Rendering shared partials
- !ruby/struct:SM::Flow::P 
  body: "Two controllers can share a set of partials and render them like this:"
- !ruby/struct:SM::Flow::VERB 
  body: "  &lt;%= render :partial =&gt; &quot;advertisement/ad&quot;, :locals =&gt; { :ad =&gt; @advertisement } %&gt;\n"
- !ruby/struct:SM::Flow::P 
  body: This will render the partial &quot;advertisement/_ad.erb&quot; regardless of which controller this is being called from.
- !ruby/struct:SM::Flow::H 
  level: 2
  text: Rendering partials with layouts
- !ruby/struct:SM::Flow::P 
  body: "Partials can have their own layouts applied to them. These layouts are different than the ones that are specified globally for the entire action, but they work in a similar fashion. Imagine a list with two types of users:"
- !ruby/struct:SM::Flow::VERB 
  body: "  &lt;%# app/views/users/index.html.erb &amp;&gt;\n  Here's the administrator:\n  &lt;%= render :partial =&gt; &quot;user&quot;, :layout =&gt; &quot;administrator&quot;, :locals =&gt; { :user =&gt; administrator } %&gt;\n\n  Here's the editor:\n  &lt;%= render :partial =&gt; &quot;user&quot;, :layout =&gt; &quot;editor&quot;, :locals =&gt; { :user =&gt; editor } %&gt;\n\n  &lt;%# app/views/users/_user.html.erb &amp;&gt;\n  Name: &lt;%= user.name %&gt;\n\n  &lt;%# app/views/users/_administrator.html.erb &amp;&gt;\n  &lt;div id=&quot;administrator&quot;&gt;\n    Budget: $&lt;%= user.budget %&gt;\n    &lt;%= yield %&gt;\n  &lt;/div&gt;\n\n  &lt;%# app/views/users/_editor.html.erb &amp;&gt;\n  &lt;div id=&quot;editor&quot;&gt;\n    Deadline: $&lt;%= user.deadline %&gt;\n    &lt;%= yield %&gt;\n  &lt;/div&gt;\n"
- !ruby/struct:SM::Flow::P 
  body: "...this will return:"
- !ruby/struct:SM::Flow::VERB 
  body: "  Here's the administrator:\n  &lt;div id=&quot;administrator&quot;&gt;\n    Budget: $&lt;%= user.budget %&gt;\n    Name: &lt;%= user.name %&gt;\n  &lt;/div&gt;\n\n  Here's the editor:\n  &lt;div id=&quot;editor&quot;&gt;\n    Deadline: $&lt;%= user.deadline %&gt;\n    Name: &lt;%= user.name %&gt;\n  &lt;/div&gt;\n"
- !ruby/struct:SM::Flow::P 
  body: "You can also apply a layout to a block within any template:"
- !ruby/struct:SM::Flow::VERB 
  body: "  &lt;%# app/views/users/_chief.html.erb &amp;&gt;\n  &lt;% render(:layout =&gt; &quot;administrator&quot;, :locals =&gt; { :user =&gt; chief }) do %&gt;\n    Title: &lt;%= chief.title %&gt;\n  &lt;% end %&gt;\n"
- !ruby/struct:SM::Flow::P 
  body: "...this will return:"
- !ruby/struct:SM::Flow::VERB 
  body: "  &lt;div id=&quot;administrator&quot;&gt;\n    Budget: $&lt;%= user.budget %&gt;\n    Title: &lt;%= chief.name %&gt;\n  &lt;/div&gt;\n"
- !ruby/struct:SM::Flow::P 
  body: As you can see, the <tt>:locals</tt> hash is shared between both the partial and its layout.
constants: []

full_name: ActionView::Partials
includes: []

instance_methods: []

name: Partials
superclass: 
