Skip to content
Browse files

Changed render_partial to take local assigns as the second parameter …

…instead of an explicit object and then the assigns

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1170 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 82456d9 commit 6ee06ebec6814576b16f6438c89fb53d557305c2 @dhh dhh committed Apr 16, 2005
Showing with 31 additions and 10 deletions.
  1. +10 −0 actionpack/CHANGELOG
  2. +5 −5 actionpack/lib/action_controller/base.rb
  3. +16 −5 actionpack/lib/action_view/partials.rb
View
10 actionpack/CHANGELOG
@@ -1,5 +1,15 @@
*SVN*
+* Changed render_partial to take local assigns as the second parameter instead of an explicit object and then the assigns. So the API changes from:
+
+ <%= render_partial "account", person, "rules" => regulations.rules %>
+
+ ...to:
+
+ <%= render_partial "account", :account => person, :rules => regulations.rules %>
+
+ The old API will still work, though, and render_partial "account" will still assume :account => @account.
+
* Added submit_to_remote that allows you to trigger an Ajax form submition at the click of the submission button, which allows for multiple targets in a single form through the use of multiple submit buttons #930 [yrashk@gmail.com]
* Fixed pagination to work with joins #1034 [scott@sigkill.org]
View
10 actionpack/lib/action_controller/base.rb
@@ -242,24 +242,24 @@ class Base
cattr_accessor :ignore_missing_templates
# Holds the request object that's primarily used to get environment variables through access like
- # <tt>@request.env["REQUEST_URI"]</tt>.
+ # <tt>request.env["REQUEST_URI"]</tt>.
attr_accessor :request
# Holds a hash of all the GET, POST, and Url parameters passed to the action. Accessed like <tt>@params["post_id"]</tt>
# to get the post_id. No type casts are made, so all values are returned as strings.
attr_accessor :params
# Holds the response object that's primarily used to set additional HTTP headers through access like
- # <tt>@response.headers["Cache-Control"] = "no-cache"</tt>. Can also be used to access the final body HTML after a template
- # has been rendered through @response.body -- useful for <tt>after_filter</tt>s that wants to manipulate the output,
+ # <tt>response.headers["Cache-Control"] = "no-cache"</tt>. Can also be used to access the final body HTML after a template
+ # has been rendered through response.body -- useful for <tt>after_filter</tt>s that wants to manipulate the output,
# such as a OutputCompressionFilter.
attr_accessor :response
- # Holds a hash of objects in the session. Accessed like <tt>@session["person"]</tt> to get the object tied to the "person"
+ # Holds a hash of objects in the session. Accessed like <tt>session[:person]</tt> to get the object tied to the "person"
# key. The session will hold any type of object as values, but the key should be a string.
attr_accessor :session
- # Holds a hash of header names and values. Accessed like <tt>@headers["Cache-Control"]</tt> to get the value of the Cache-Control
+ # Holds a hash of header names and values. Accessed like <tt>headers["Cache-Control"]</tt> to get the value of the Cache-Control
# directive. Values should always be specified as strings.
attr_accessor :headers
View
21 actionpack/lib/action_view/partials.rb
@@ -1,14 +1,25 @@
module ActionView
# 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. In the template for
- # Advertiser#buy, we could have:
+ # prefixed with an underscore -- as to separate them from regular templates that could be rendered on their own.
+ #
+ # In a template for Advertiser#account:
+ #
+ # <%= render_partial "account" %>
+ #
+ # This would render "advertiser/_account.rhtml" and pass the instance variable @account in as a local variable +account+ to
+ # the template for display.
+ #
+ # In another template for Advertiser#buy, we could have:
+ #
+ # <%= render_partial "account", :account => @buyer %>
#
# <% for ad in @advertisements %>
- # <%= render_partial "ad", ad %>
+ # <%= render_partial "ad", :ad => ad %>
# <% end %>
#
- # This would render "advertiser/_ad.rhtml" and pass the local variable +ad+ to the template for display.
+ # This would first render "advertiser/_account.rhtml" with @buyer passed in as the local variable +account+, then render
+ # "advertiser/_ad.rhtml" and pass the local variable +ad+ to the template for display.
#
# == Rendering a collection of partials
#
@@ -27,7 +38,7 @@ module ActionView
#
# Two controllers can share a set of partials and render them like this:
#
- # <%= render_partial "advertisement/ad", ad %>
+ # <%= render_partial "advertisement/ad", :ad => @advertisement %>
#
# This will render the partial "advertisement/_ad.rhtml" regardless of which controller this is being called from.
module Partials

0 comments on commit 6ee06eb

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