{"issue":{"pull_request":{"diff_url":null,"html_url":null,"patch_url":null},"state":"open","user":{"avatar_url":"https://secure.gravatar.com/avatar/aa52c36976ef60f237e4aa5e386e36f8?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"aa52c36976ef60f237e4aa5e386e36f8","url":"https://api.github.com/users/pfeiffer","login":"pfeiffer","id":195925},"milestone":null,"assignee":null,"updated_at":"2011-11-07T09:28:55Z","labels":[],"comments":0,"closed_at":null,"url":"https://api.github.com/repos/jcasimir/draper/issues/78","body":"I sometimes find it very handy to add decoration methods to the collection object, as well as the individual objects of the collection.\r\n\r\nAs an example, lets say I have a shop and want to display a list of orders received recently in a table view. I also want to display a summary in the bottom of the table displaying total order value of the visible orders. Typically I would iterate through the order collection and output the individual order as a row, while summing up the `amount`'s into some instance variable.\r\n\r\nWe can do better - a proposed example for controller and view code:\r\n\r\n**Controller:**\r\n\r\n```\r\n@orders = OrderCollectionDecorator.new(@orders)\r\n```\r\n\r\n**View:**\r\n\r\n```\r\n%table\r\n  %tbody\r\n    - @orders.each do |order|\r\n      %tr\r\n        %td= order.customer\r\n        %td= order.amount\r\n  %tfoot\r\n    %tr\r\n      %td \"Total value of orders:\"\r\n      %td= @orders.amount\r\n```\r\n\r\nIn this case the last `amount`, summarizing the total order amount of the orders, is a decorated method on the collection, rather than on the individual models in the collection. The simplicity offered gets even greater when the need arises for more summarizing methods eg. average order value, total number of items in orders etc.\r\n\r\nAt the moment there's no easy way to implement decoration methods on the collection.\r\n\r\nWhat do you think of this idiom? Is there any way we can achieve it with Draper?\r\n\r\nA quick and easy step in the right direction would be to extract the methods of `Draper::DecoratedEnumerableProxy` into a module, so it as least could be included in the collection decorators. I can certainly do this and open a pull request, but I'd like to get your inputs before hand.","html_url":"https://github.com/jcasimir/draper/issues/78","number":78,"title":"Feature proposal: Decorate collection proxy","id":2160839,"created_at":"2011-11-07T09:28:55Z"},"action":"opened"}