diff options
author | José Valim <jose.valim@gmail.com> | 2009-12-26 11:02:41 +0100 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2009-12-26 14:11:04 +0100 |
commit | ff1a1c0b4d08567e8aeaef698003b5cd96d79686 (patch) | |
tree | f070fc38275cd1bc9280b0fdf4d3b9c82b51f4fd /actionpack/lib/action_view | |
parent | c86424a72d229c519179a6cdf1d37e93b46e1e38 (diff) | |
download | rails-ff1a1c0b4d08567e8aeaef698003b5cd96d79686.tar.gz rails-ff1a1c0b4d08567e8aeaef698003b5cd96d79686.tar.bz2 rails-ff1a1c0b4d08567e8aeaef698003b5cd96d79686.zip |
Optimize <%= render(@posts) %>.
Diffstat (limited to 'actionpack/lib/action_view')
-rw-r--r-- | actionpack/lib/action_view/render/partials.rb | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/actionpack/lib/action_view/render/partials.rb b/actionpack/lib/action_view/render/partials.rb index 04edb9ab44..eb035ae2dd 100644 --- a/actionpack/lib/action_view/render/partials.rb +++ b/actionpack/lib/action_view/render/partials.rb @@ -233,7 +233,17 @@ module ActionView spacer = find_template(@options[:spacer_template]).render(@view, @locals) end - result = template ? collection_with_template(template) : collection_without_template + result = if template + collection_with_template(template) + else + paths = @collection.map { |o| partial_path(o) } + + if paths.uniq.size == 1 + collection_with_template(find_template(paths.first)) + else + collection_without_template(paths) + end + end result.join(spacer).html_safe! end @@ -254,12 +264,12 @@ module ActionView segments end - def collection_without_template + def collection_without_template(collection_paths) segments, locals, as = [], @locals, @options[:as] index, template = -1, nil - @collection.each do |object| - template = find_template(partial_path(object)) + @collection.each_with_index do |object, i| + template = find_template(collection_paths[i]) locals[template.counter_name] = (index += 1) locals[template.variable_name] = object |