U:RDoc::NormalModule[iI"Partials:EFI"ActionView::Partials;F0o:RDoc::Markup::Document:@parts[o;;[ZS:RDoc::Markup::Heading:
leveli:	textI"Action View Partials;To:RDoc::Markup::BlankLine o:RDoc::Markup::Paragraph;[	I"sThere's also a convenience method for rendering sub templates within the current controller that depends on a ;TI"qsingle object (we call this kind of sub templates for partials). It relies on the fact that partials should ;TI"kfollow the naming convention of being prefixed with an underscore -- as to separate them from regular ;TI"3templates that could be rendered on their own.;T@o;;[I"*In a template for Advertiser#account:;T@o:RDoc::Markup::Verbatim;[I")<%= render :partial => "account" %>
;T:@format0o;;[I"pThis would render "advertiser/_account.erb" and pass the instance variable @account in as a local variable ;TI"++account+ to the template for display.;T@o;;[I";In another template for Advertiser#buy, we could have:;T@o;;[
I"L<%= render :partial => "account", :locals => { :account => @buyer } %>
;TI"
;TI"%<% for ad in @advertisements %>
;TI"@  <%= render :partial => "ad", :locals => { :ad => ad } %>
;TI"<% end %>
;T;0o;;[I"sThis would first render "advertiser/_account.erb" with @buyer passed in as the local variable +account+, then ;TI"^render "advertiser/_ad.erb" and pass the local variable +ad+ to the template for display.;T@S;	;
i;I" The :as and :object options;T@o;;[I"rBy default PartialRenderer uses the template name for the local name of the object passed into the template. ;TI"-These examples are effectively the same:;T@o;;[I"R<%= render :partial => "contract", :locals => { :contract  => @contract } %>
;TI"
;TI"*<%= render :partial => "contract" %>
;T;0o;;[I"dBy specifying the :as option we can change the way the local variable is namedin the template. ;TI"-These examples are effectively the same:;T@o;;[I":<%= render :partial => "contract", :as => :agreement
;TI"
;TI"O<%= render :partial => "contract", :locals => { :agreement => @contract }
;T;0o;;[I"bThe :object option can be used to directly specify which object is rendered into the partial.;T@o;;[I"CRevisiting a previous example we could have written this code.;T@o;;[
I"<<%= render :partial => "account", :object => @buyer %>
;TI"
;TI"%<% for ad in @advertisements %>
;TI"5  <%= render :partial => "ad", :object => ad %>
;TI"<% end %>
;T;0o;;[I"nThe :object and :as options can be used together. We might have a partial which we have named genericly, ;TI"=such as 'form'. Using :object and :as together helps us.;T@o;;[I"N<%= render :partial => "form", :object => @contract, :as => :contract %>
;T;0S;	;
i;I"'Rendering a collection of partials;T@o;;[	I"qThe example of partial use describes a familiar pattern where a template needs to iterate over an array and ;TI"orender a sub template for each of the elements. This pattern has been implemented as a single method that ;TI"raccepts an array and renders a partial by the same name as the elements contained within. So the three-lined ;TI"Eexample in "Using partials" can be rewritten with a single line:;T@o;;[I"D<%= render :partial => "ad", :collection => @advertisements %>
;T;0o;;[I"lThis will render "advertiser/_ad.erb" and pass the local variable +ad+ to the template for display. An ;TI"diteration counter will automatically be made available to the template with a name of the form ;TI"f+partial_name_counter+. In the case of the example above, the template would be fed +ad_counter+.;T@o;;[I"8The :as option may be used when rendering partials.;T@o;;[I"vAlso, you can specify a partial which will be render as a spacer between each element by passing partial name to ;TI"p+:spacer_template+. The following example will render "advertiser/_ad_divider.erb" between each ad partial.;T@o;;[I"f<%= render :partial => "ad", :collection => @advertisements, :spacer_template => "ad_divider" %>
;T;0o;;[I"oNOTE: Due to backwards compatibility concerns, the collection can't be one of hashes. Normally you'd also ;TI"=just keep domain objects, like Active Records, in there.;T@S;	;
i;I"Rendering shared partials;T@o;;[I"KTwo controllers can share a set of partials and render them like this:;T@o;;[I"X<%= render :partial => "advertisement/ad", :locals => { :ad => @advertisement } %>
;T;0o;;[I"sThis will render the partial "advertisement/_ad.erb" regardless of which controller this is being called from.;T@S;	;
i;I"0Rendering objects with the RecordIdentifier;T@o;;[I"rInstead of explicitly naming the location of a partial, you can also let the RecordIdentifier do the work if ;TI"Ryou're following its conventions for RecordIdentifier#partial_path. Examples:;T@o;;[I"S# @account is an Account instance, so it uses the RecordIdentifier to replace
;TI"X# <%= render :partial => "accounts/account", :locals => { :account => @account} %>
;TI"(<%= render :partial => @account %>
;TI"
;TI"X# @posts is an array of Post instances, so it uses the RecordIdentifier to replace
;TI"E# <%= render :partial => "posts/post", :collection => @posts %>
;TI"&<%= render :partial => @posts %>
;T;0S;	;
i;I"Rendering the default case;T@o;;[I"uIf you're not going to be using any of the options like collections or layouts, you can also use the short-hand ;TI"5defaults of render to render partials. Examples:;T@o;;[I"6# Instead of <%= render :partial => "account" %>
;TI"<%= render "account" %>
;TI"
;TI"Y# Instead of <%= render :partial => "account", :locals => { :account => @buyer } %>
;TI"1<%= render "account", :account => @buyer %>
;TI"
;TI"S# @account is an Account instance, so it uses the RecordIdentifier to replace
;TI"Y# <%= render :partial => "accounts/account", :locals => { :account => @account } %>
;TI"<%= render(@account) %>
;TI"
;TI"X# @posts is an array of Post instances, so it uses the RecordIdentifier to replace
;TI"E# <%= render :partial => "posts/post", :collection => @posts %>
;TI"<%= render(@posts) %>
;T;0S;	;
i;I"$Rendering partials with layouts;T@o;;[I"mPartials can have their own layouts applied to them. These layouts are different than the ones that are ;TI"qspecified globally for the entire action, but they work in a similar fashion. Imagine a list with two types ;TI"of users:;T@o;;[I"+<%# app/views/users/index.html.erb &>
;TI"Here's the administrator:
;TI"i<%= render :partial => "user", :layout => "administrator", :locals => { :user => administrator } %>
;TI"
;TI"Here's the editor:
;TI"[<%= render :partial => "user", :layout => "editor", :locals => { :user => editor } %>
;TI"
;TI"+<%# app/views/users/_user.html.erb &>
;TI"Name: <%= user.name %>
;TI"
;TI"4<%# app/views/users/_administrator.html.erb &>
;TI"<div id="administrator">
;TI"#  Budget: $<%= user.budget %>
;TI"  <%= yield %>
;TI"</div>
;TI"
;TI"-<%# app/views/users/_editor.html.erb &>
;TI"<div id="editor">
;TI"&  Deadline: <%= user.deadline %>
;TI"  <%= yield %>
;TI"</div>
;T;0o;;[I"...this will return:;T@o;;[I"Here's the administrator:
;TI"<div id="administrator">
;TI"#  Budget: $<%= user.budget %>
;TI"  Name: <%= user.name %>
;TI"</div>
;TI"
;TI"Here's the editor:
;TI"<div id="editor">
;TI"&  Deadline: <%= user.deadline %>
;TI"  Name: <%= user.name %>
;TI"</div>
;T;0o;;[I"@You can also apply a layout to a block within any template:;T@o;;[	I",<%# app/views/users/_chief.html.erb &>
;TI"Q<%= render(:layout => "administrator", :locals => { :user => chief }) do %>
;TI"!  Title: <%= chief.title %>
;TI"<% end %>
;T;0o;;[I"...this will return:;T@o;;[	I"<div id="administrator">
;TI"#  Budget: $<%= user.budget %>
;TI"   Title: <%= chief.name %>
;TI"</div>
;T;0o;;[I"aAs you can see, the <tt>:locals</tt> hash is shared between both the partial and its layout.;T@o;;[I"lIf you pass arguments to "yield" then this will be passed to the block. One way to use this is to pass ;TI"6an array to layout and treat it as an enumerable.;T@o;;[I"+<%# app/views/users/_user.html.erb &>
;TI"<div class="user">
;TI"#  Budget: $<%= user.budget %>
;TI"  <%= yield user %>
;TI"</div>
;TI"
;TI"+<%# app/views/users/index.html.erb &>
;TI"/<%= render :layout => @users do |user| %>
;TI"   Title: <%= user.title %>
;TI"<% end %>
;T;0o;;[I"cThis will render the layout for each user and yield to the block, passing the user, each time.;T@o;;[I"kYou can also yield multiple times in one layout and use block arguments to differentiate the sections.;T@o;;[I"+<%# app/views/users/_user.html.erb &>
;TI"<div class="user">
;TI""  <%= yield user, :header %>
;TI"#  Budget: $<%= user.budget %>
;TI""  <%= yield user, :footer %>
;TI"</div>
;TI"
;TI"+<%# app/views/users/index.html.erb &>
;TI"8<%= render :layout => @users do |user, section| %>
;TI")  <%- case section when :header -%>
;TI""    Title: <%= user.title %>
;TI"  <%- when :footer -%>
;TI"(    Deadline: <%= user.deadline %>
;TI"  <%- end -%>
;TI"<% end %>;T;0:
@fileI"'lib/action_view/render/partials.rb;T:0@omit_headings_from_table_of_contents_below0;0;0[ [ [ [[I"
class;T[[:public[ [:protected[ [:private[ [I"instance;T[[;[ [;[ [;[ [[I"ActiveSupport::Concern;To;;[ ;@;0I"'lib/action_view/render/partials.rb;T[U:RDoc::Context::Section[i 0o;;[ ;0;0[@I"ActionView;FcRDoc::NormalModule