aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view/partials.rb
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2008-04-01 00:50:09 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2008-04-01 00:50:09 +0000
commit9cc478a2547bec5b72fa2a4b36b2f8e627373a74 (patch)
tree5f23c1449d7701acdee3b3f411412634f042b691 /actionpack/lib/action_view/partials.rb
parent2681d55e407233c126ff8f0a5956c302b3acfb91 (diff)
downloadrails-9cc478a2547bec5b72fa2a4b36b2f8e627373a74.tar.gz
rails-9cc478a2547bec5b72fa2a4b36b2f8e627373a74.tar.bz2
rails-9cc478a2547bec5b72fa2a4b36b2f8e627373a74.zip
Support render :partial => collection of heterogeneous elements. Closes #11491.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@9177 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib/action_view/partials.rb')
-rw-r--r--actionpack/lib/action_view/partials.rb32
1 files changed, 25 insertions, 7 deletions
diff --git a/actionpack/lib/action_view/partials.rb b/actionpack/lib/action_view/partials.rb
index 7f1963fb29..a92b05508a 100644
--- a/actionpack/lib/action_view/partials.rb
+++ b/actionpack/lib/action_view/partials.rb
@@ -113,9 +113,8 @@ module ActionView
render_partial(builder_partial_path, object_assigns, (local_assigns || {}).merge(builder_partial_path.to_sym => partial_path))
when Array, ActiveRecord::Associations::AssociationCollection, ActiveRecord::Associations::HasManyThroughAssociation
if partial_path.any?
- path = ActionController::RecordIdentifier.partial_path(partial_path.first)
collection = partial_path
- render_partial_collection(path, collection, nil, local_assigns)
+ render_partial_collection(nil, collection, nil, local_assigns)
else
""
end
@@ -126,15 +125,34 @@ module ActionView
def render_partial_collection(partial_path, collection, partial_spacer_template = nil, local_assigns = {}) #:nodoc:
return " " if collection.empty?
-
+
local_assigns = local_assigns ? local_assigns.clone : {}
- template = ActionView::PartialTemplate.new(self, partial_path, nil, local_assigns)
-
spacer = partial_spacer_template ? render(:partial => partial_spacer_template) : ''
-
+
+ if partial_path.nil?
+ render_partial_collection_with_unknown_partial_path(collection, local_assigns, spacer)
+ else
+ render_partial_collection_with_known_partial_path(collection, partial_path, local_assigns, spacer)
+ end.join(spacer)
+ end
+
+ def render_partial_collection_with_known_partial_path(collection, partial_path, local_assigns, spacer)
+ template = ActionView::PartialTemplate.new(self, partial_path, nil, local_assigns)
collection.map do |element|
template.render_member(element)
- end.join(spacer)
+ end
+ end
+
+ def render_partial_collection_with_unknown_partial_path(collection, local_assigns, spacer)
+ templates = Hash.new
+ i = 0
+ collection.map do |element|
+ partial_path = ActionController::RecordIdentifier.partial_path(element)
+ template = templates[partial_path] ||= ActionView::PartialTemplate.new(self, partial_path, nil, local_assigns)
+ template.counter = i
+ i += 1
+ template.render_member(element)
+ end
end
end
end