From 5b67a2690b4def6457e0fc27f216049dec35c0b9 Mon Sep 17 00:00:00 2001 From: Andrew Haines Date: Mon, 31 Dec 2012 17:44:41 +0000 Subject: [PATCH] Add example of delegation to source [ci skip] --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 8999282..a5c3f63 100644 --- a/README.md +++ b/README.md @@ -158,6 +158,14 @@ end Draper guesses the decorator used for each item from the name of the collection decorator ("ArticlesDecorator" becomes "ArticleDecorator"). If that fails, it falls back to using each item's `decorate` method. Alternatively, you can specify a decorator by overriding the collection decorator's `decorator_class` method. +Some pagination gems add methods to `ActiveRecord::Relation`. For example, [Kaminari](https://github.com/amatsuda/kaminari)'s `paginate` helper method requires the collection to implement `current_page`, `total_pages`, and `limit_value`. To expose these on a collection decorator, you can simply delegate to `source`: + +```ruby +class PaginatingDecorator < Draper::CollectionDecorator + delegate :current_page, :total_pages, :limit_value, to: :source +end +``` + ### Handy shortcuts You can automatically decorate associated models: