diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2004-12-12 11:48:01 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2004-12-12 11:48:01 +0000 |
commit | 9ee94ab13a3f02fa3097f9bd5c57ab223e3fbf97 (patch) | |
tree | 902cd57dce8405050ce8a52da2a9940e15935330 /actionpack/lib/action_view | |
parent | ecb1d5afce4724760f3f8309f07740bc83ad56b4 (diff) | |
download | rails-9ee94ab13a3f02fa3097f9bd5c57ab223e3fbf97.tar.gz rails-9ee94ab13a3f02fa3097f9bd5c57ab223e3fbf97.tar.bz2 rails-9ee94ab13a3f02fa3097f9bd5c57ab223e3fbf97.zip |
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
Diffstat (limited to 'actionpack/lib/action_view')
-rw-r--r-- | actionpack/lib/action_view/partials.rb | 9 |
1 files changed, 8 insertions, 1 deletions
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 |