Adding collection_decorator_class to README.md

Adding how to use a PaginatingDecorator (extending Draper::CollectionDecorator) on a class extending Draper::Decorator to README.md
This explains how to use ArticleDecorator.decorate_collection(@articles.paginate(page: params[:page])) and have your @articles respond to pagination methods whilst individual articles get decorated
This commit is contained in:
Rennan Oliveira 2016-03-22 18:01:06 -03:00
parent 57a514133b
commit d45f11d70e
1 changed files with 13 additions and 0 deletions

View File

@ -276,6 +276,19 @@ omitted.
delegate :current_page, :per_page, :offset, :total_entries, :total_pages
```
If needed, you can then set the collection_decorator_class of your CustomDecorator as follows:
```ruby
class ArticleDecorator < Draper::Decorator
def self.collection_decorator_class
PaginatingDecorator
end
end
ArticleDecorator.decorate_collection(@articles.paginate)
# => Collection decorated by PaginatingDecorator
# => Members decorated by ArticleDecorator
```
### Decorating Associated Objects
You can automatically decorate associated models when the primary model is