From 9ee94ab13a3f02fa3097f9bd5c57ab223e3fbf97 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sun, 12 Dec 2004 11:48:01 +0000 Subject: Added that render_partial will always by default include a counter with value 1 unless there is a counter passed in via the local_assigns hash that overrides it. As a result, render_collection_of_partials can still be written in terms of render_partial and partials that make use of a counter can be called without problems from both render_collection_of_partials as well as render_partial #295 [marcel] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@116 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/lib/action_view/partials.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/actionpack/lib/action_view/partials.rb b/actionpack/lib/action_view/partials.rb index 96bde4c6d3..927ef2a977 100644 --- a/actionpack/lib/action_view/partials.rb +++ b/actionpack/lib/action_view/partials.rb @@ -34,13 +34,16 @@ module ActionView def render_partial(partial_path, object = nil, local_assigns = {}) path, partial_name = partial_pieces(partial_path) object ||= controller.instance_variable_get("@#{partial_name}") + counter_name = partial_counter_name(partial_name) + local_assigns = local_assigns.merge(counter_name => 1) unless local_assigns.has_key?(counter_name) render("#{path}/_#{partial_name}", { partial_name => object }.merge(local_assigns)) end def render_collection_of_partials(partial_name, collection, partial_spacer_template = nil) collection_of_partials = Array.new + counter_name = partial_counter_name(partial_name) collection.each_with_index do |element, counter| - collection_of_partials.push(render_partial(partial_name, element, "#{partial_name.split("/").last}_counter" => counter)) + collection_of_partials.push(render_partial(partial_name, element, counter_name => counter)) end return nil if collection_of_partials.empty? @@ -60,5 +63,9 @@ module ActionView return controller.send(:controller_name), partial_path end end + + def partial_counter_name(partial_name) + "#{partial_name.split('/').last}_counter" + end end end -- cgit v1.2.3