jcasimir/draper — Issue #135: Collection decoration is lost when using ActiveSupport's Array#in_groups_of
Author: pguegan
Created: 2012-03-01 18:01:40+00:00
State: open

Using draper 0.10.0

Given this simple situation:

class ItemsController < ApplicationController
def index
@items = ItemDecorator.decorate Item.all
end
end

In the view, I want to group my items (here 3 by 3) by using [ActiveSupport's Array#in_groups_of](http://rails.rubyonrails.org/classes/ActiveSupport/CoreExtensions/Array/Grouping.html#M000833) (so I can display them in a grid for example) :

<% @items.in_groups_of(3, false).each do |group| %>
<% group.each do |item| %>
<%= item.a_method_from_decorator %> # This fails!
<% end %>
<% end %>

The third line fails to execute, since the item is not decorated and the method `a_method_from_decorator` is undefined. This is because the sub-collections (groups) are not wrapped in a `DecoratedEnumerableProxy`.

Can the method `in_groups_of` be patched (for example [like this](https://github.com/pguegan/draper/blob/master/lib/draper/decorated_enumerable_proxy.rb#L13)) so it returns groups of wrapped collections? I don't know if draper is aimed at supporting all ActiveSupport methods on Array class, but I think it could be a nice functionality.

I also could provide a pull request if you agree with this proposition.