aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view/partials.rb
diff options
context:
space:
mode:
authorRyan Bates <ryan@railscasts.com>2008-08-17 19:29:24 -0500
committerJoshua Peek <josh@joshpeek.com>2008-08-17 19:29:24 -0500
commit38c7d73e73d569211c4dfadf96fc295a925b7c9c (patch)
tree9400fbbd277dafdde822fb9d3968f30764dbe9da /actionpack/lib/action_view/partials.rb
parentdbb0abfb7e9eb9a63b721a38625e3eff66ced49d (diff)
downloadrails-38c7d73e73d569211c4dfadf96fc295a925b7c9c.tar.gz
rails-38c7d73e73d569211c4dfadf96fc295a925b7c9c.tar.bz2
rails-38c7d73e73d569211c4dfadf96fc295a925b7c9c.zip
pass yielded arguments to block for ActionView::Base#render with :layout [#847 state:resolved]
Signed-off-by: Joshua Peek <josh@joshpeek.com>
Diffstat (limited to 'actionpack/lib/action_view/partials.rb')
-rw-r--r--actionpack/lib/action_view/partials.rb38
1 files changed, 36 insertions, 2 deletions
diff --git a/actionpack/lib/action_view/partials.rb b/actionpack/lib/action_view/partials.rb
index 894b88534c..b661a62677 100644
--- a/actionpack/lib/action_view/partials.rb
+++ b/actionpack/lib/action_view/partials.rb
@@ -68,7 +68,7 @@ module ActionView
#
# <%# app/views/users/_editor.html.erb &>
# <div id="editor">
- # Deadline: $<%= user.deadline %>
+ # Deadline: <%= user.deadline %>
# <%= yield %>
# </div>
#
@@ -82,7 +82,7 @@ module ActionView
#
# Here's the editor:
# <div id="editor">
- # Deadline: $<%= user.deadline %>
+ # Deadline: <%= user.deadline %>
# Name: <%= user.name %>
# </div>
#
@@ -101,6 +101,40 @@ module ActionView
# </div>
#
# As you can see, the <tt>:locals</tt> hash is shared between both the partial and its layout.
+ #
+ # If you pass arguments to "yield" then this will be passed to the block. One way to use this is to pass
+ # an array to layout and treat it as an enumerable.
+ #
+ # <%# app/views/users/_user.html.erb &>
+ # <div class="user">
+ # Budget: $<%= user.budget %>
+ # <%= yield user %>
+ # </div>
+ #
+ # <%# app/views/users/index.html.erb &>
+ # <% render :layout => @users do |user| %>
+ # Title: <%= user.title %>
+ # <% end %>
+ #
+ # This will render the layout for each user and yield to the block, passing the user, each time.
+ #
+ # You can also yield multiple times in one layout and use block arguments to differentiate the sections.
+ #
+ # <%# app/views/users/_user.html.erb &>
+ # <div class="user">
+ # <%= yield user, :header %>
+ # Budget: $<%= user.budget %>
+ # <%= yield user, :footer %>
+ # </div>
+ #
+ # <%# app/views/users/index.html.erb &>
+ # <% render :layout => @users do |user, section| %>
+ # <%- case section when :header -%>
+ # Title: <%= user.title %>
+ # <%- when :footer -%>
+ # Deadline: <%= user.deadline %>
+ # <%- end -%>
+ # <% end %>
module Partials
extend ActiveSupport::Memoizable