1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

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
This commit is contained in:
David Heinemeier Hansson 2004-12-12 11:48:01 +00:00
parent ecb1d5afce
commit 9ee94ab13a

View file

@ -34,13 +34,16 @@ module ActionView
def render_partial(partial_path, object = nil, local_assigns = {}) def render_partial(partial_path, object = nil, local_assigns = {})
path, partial_name = partial_pieces(partial_path) path, partial_name = partial_pieces(partial_path)
object ||= controller.instance_variable_get("@#{partial_name}") 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)) render("#{path}/_#{partial_name}", { partial_name => object }.merge(local_assigns))
end end
def render_collection_of_partials(partial_name, collection, partial_spacer_template = nil) def render_collection_of_partials(partial_name, collection, partial_spacer_template = nil)
collection_of_partials = Array.new collection_of_partials = Array.new
counter_name = partial_counter_name(partial_name)
collection.each_with_index do |element, counter| 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 end
return nil if collection_of_partials.empty? return nil if collection_of_partials.empty?
@ -60,5 +63,9 @@ module ActionView
return controller.send(:controller_name), partial_path return controller.send(:controller_name), partial_path
end end
end end
def partial_counter_name(partial_name)
"#{partial_name.split('/').last}_counter"
end
end end
end end