Permalink
Browse files

Move layout logic with collection to be handled only with explicit te…

…mplate is given

Layout is never an available option when rendering with the shortcut
`render @collection`.
  • Loading branch information...
1 parent 0568fb5 commit 228f9910389cad7fe0dd7f2bd010fe654f794b37 @carlosantoniodasilva committed Apr 27, 2012
Showing with 8 additions and 15 deletions.
  1. +8 −15 actionpack/lib/action_view/renderer/partial_renderer.rb
@@ -282,21 +282,7 @@ def render_collection
spacer = find_template(@options[:spacer_template]).render(@view, @locals)
end
- if layout = @options[:layout]
- layout = find_template(layout, @locals.keys + [@variable, @variable_counter])
- end
-
result = @template ? collection_with_template : collection_without_template
-
- if layout
- locals = @locals
- result.map! do |content|
- locals[@variable] = @collection[result.index(content)]
- locals[@variable_counter] = result.index(content)
- layout.render(@view, @locals) { content }
- end
- end
-
result.join(spacer).html_safe
end
@@ -391,12 +377,19 @@ def collection_with_template
segments, locals, template = [], @locals, @template
as, counter = @variable, @variable_counter
+ if layout = @options[:layout]
+ layout = find_template(layout, @locals.keys + [@variable, @variable_counter])
+ end
+
locals[counter] = -1
@collection.each do |object|
locals[counter] += 1
locals[as] = object
- segments << template.render(@view, locals)
+
+ content = template.render(@view, locals)
+ content = layout.render(@view, locals) { content } if layout
+ segments << content
end
segments

0 comments on commit 228f991

Please sign in to comment.