aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view/partial_template.rb
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2008-07-02 16:38:50 +0100
committerPratik Naik <pratiknaik@gmail.com>2008-07-02 16:40:42 +0100
commit2b43620e3c1352028f19550fcde4632d65cbd191 (patch)
treeb28ddcc92eae7fe9ceea11c2f55b1956f5d4efc7 /actionpack/lib/action_view/partial_template.rb
parent4f75840d72b96fff34d65b59480da7d6c7494120 (diff)
downloadrails-2b43620e3c1352028f19550fcde4632d65cbd191.tar.gz
rails-2b43620e3c1352028f19550fcde4632d65cbd191.tar.bz2
rails-2b43620e3c1352028f19550fcde4632d65cbd191.zip
Add :as option to render a collection of partials with a custom local variable name. [#509 state:resolved] [Simon Jefford, Pratik Naik]
Diffstat (limited to 'actionpack/lib/action_view/partial_template.rb')
-rw-r--r--actionpack/lib/action_view/partial_template.rb9
1 files changed, 6 insertions, 3 deletions
diff --git a/actionpack/lib/action_view/partial_template.rb b/actionpack/lib/action_view/partial_template.rb
index 0cf996ca04..3513244ecb 100644
--- a/actionpack/lib/action_view/partial_template.rb
+++ b/actionpack/lib/action_view/partial_template.rb
@@ -1,9 +1,10 @@
module ActionView #:nodoc:
class PartialTemplate < Template #:nodoc:
- attr_reader :variable_name, :object
+ attr_reader :variable_name, :object, :as
- def initialize(view, partial_path, object = nil, locals = {})
+ def initialize(view, partial_path, object = nil, locals = {}, as = nil)
@view_controller = view.controller if view.respond_to?(:controller)
+ @as = as
set_path_and_variable_name!(partial_path)
super(view, @path, true, locals)
add_object_to_local_assigns!(object)
@@ -22,10 +23,11 @@ module ActionView #:nodoc:
end
def render_member(object)
- @locals[:object] = @locals[@variable_name] = object
+ @locals[:object] = @locals[@variable_name] = @locals[as] = object
template = render_template
@locals[@counter_name] += 1
+ @locals.delete(as)
@locals.delete(@variable_name)
@locals.delete(:object)
@@ -45,6 +47,7 @@ module ActionView #:nodoc:
else
object
end || @view_controller.instance_variable_get("@#{variable_name}")
+ @locals[as] ||= @locals[:object] if as
end
def set_path_and_variable_name!(partial_path)