aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorYehuda Katz <wycats@gmail.com>2009-08-10 08:57:44 -0400
committerYehuda Katz <wycats@gmail.com>2009-08-11 15:03:53 -0700
commit9e62d6d1c0c53e8b03c9659500e2b5549a1fd2ec (patch)
tree6a66da1a90a714eff5fb1be3e9227e75eee1976e /actionpack
parent945a7df9f8ad2986ba2351b331a9f7225dfaf61c (diff)
downloadrails-9e62d6d1c0c53e8b03c9659500e2b5549a1fd2ec.tar.gz
rails-9e62d6d1c0c53e8b03c9659500e2b5549a1fd2ec.tar.bz2
rails-9e62d6d1c0c53e8b03c9659500e2b5549a1fd2ec.zip
Tentatively accept the ":as or :object, but not both" solution
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_view/render/partials.rb43
-rw-r--r--actionpack/test/fixtures/test/_customer_with_var.erb2
2 files changed, 22 insertions, 23 deletions
diff --git a/actionpack/lib/action_view/render/partials.rb b/actionpack/lib/action_view/render/partials.rb
index 2aa3bd7db8..83175ab4cf 100644
--- a/actionpack/lib/action_view/render/partials.rb
+++ b/actionpack/lib/action_view/render/partials.rb
@@ -184,6 +184,7 @@ module ActionView
def initialize(view_context, options, block)
partial = options[:partial]
+ @memo = {}
@view = view_context
@options = options
@locals = options[:locals] || {}
@@ -222,41 +223,39 @@ module ActionView
def collection_with_template(template)
options = @options
- segments, locals, as = [], @locals, options[:as]
+ segments, locals, as = [], @locals, options[:as] || :object
- [].tap do |segments|
- variable_name = template.variable_name
- counter_name = template.counter_name
- locals[counter_name] = -1
+ variable_name = template.variable_name
+ counter_name = template.counter_name
+ locals[counter_name] = -1
- collection.each do |object|
- locals[counter_name] += 1
- locals[variable_name] = object
- locals[as] = object if as
+ collection.each do |object|
+ locals[counter_name] += 1
+ locals[variable_name] = object
+ locals[as] = object if as
- segments << template.render(@view, locals)
- end
+ segments << template.render(@view, locals)
end
+ segments
end
def collection_without_template
options = @options
- segments, locals, as = [], @locals, options[:as]
+ segments, locals, as = [], @locals, options[:as] || :object
index, template = -1, nil
- [].tap do |segments|
- collection.each do |object|
- template = find_template(partial_path(object))
- locals[template.counter_name] = (index += 1)
- locals[template.variable_name] = object
- locals[as] = object if as
-
- segments << template.render(@view, locals)
- end
+ collection.each do |object|
+ template = find_template(partial_path(object))
+ locals[template.counter_name] = (index += 1)
+ locals[template.variable_name] = object
+ locals[as] = object if as
- @options[:_template] = template
+ segments << template.render(@view, locals)
end
+
+ @options[:_template] = template
+ segments
end
def render_template(template, object = @object)
diff --git a/actionpack/test/fixtures/test/_customer_with_var.erb b/actionpack/test/fixtures/test/_customer_with_var.erb
index 3379246b7e..c28824936b 100644
--- a/actionpack/test/fixtures/test/_customer_with_var.erb
+++ b/actionpack/test/fixtures/test/_customer_with_var.erb
@@ -1 +1 @@
-<%= customer.name %> <%= object.name %> <%= customer_with_var.name %> \ No newline at end of file
+<%= customer.name %> <%= customer.name %> <%= customer_with_var.name %> \ No newline at end of file