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:
parent
57a514133b
commit
d45f11d70e
13
README.md
13
README.md
|
@ -276,6 +276,19 @@ omitted.
|
||||||
delegate :current_page, :per_page, :offset, :total_entries, :total_pages
|
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
|
### Decorating Associated Objects
|
||||||
|
|
||||||
You can automatically decorate associated models when the primary model is
|
You can automatically decorate associated models when the primary model is
|
||||||
|
|
Loading…
Reference in New Issue