Skip to content
Browse files

Added that render_partial will always by default include a counter wi…

…th 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
  • Loading branch information...
1 parent ecb1d5a commit 9ee94ab13a3f02fa3097f9bd5c57ab223e3fbf97 @dhh dhh committed
Showing with 8 additions and 1 deletion.
  1. +8 −1 actionpack/lib/action_view/partials.rb
View
9 actionpack/lib/action_view/partials.rb
@@ -34,13 +34,16 @@ module Partials
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 @@ def partial_pieces(partial_path)
return controller.send(:controller_name), partial_path
end
end
+
+ def partial_counter_name(partial_name)
+ "#{partial_name.split('/').last}_counter"
+ end
end
end

0 comments on commit 9ee94ab

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