I’m working with kaminari today, and I spent a bit of time getting Draper to co-operate with the pagination. This is a fairly well documented issue, but I figured I’d post about this for my own future reference.
The issue: getting kaminari methods (such as current_page, total_pages, etc) to work on a decorated collection.
The solution: We need to delegate the kaminari methods, so that Draper knows to ignore them.
How to do this?
- Create a separate PaginatingDecorator that inherits from CollectionDraper, and delegate the kaminari methods.
|class PaginatingDecorator < Draper::CollectionDecorator|
|delegate :current_page, :total_pages, :limit_value|
- In your ApplicationDecorator class, make sure that CollectionDecorator knows to look at PaginatingDecorator.
|class ApplicationDecorator < Draper::Decorator|
- If it’s not already the case, make sure your decorator inherits from ApplicationDecorator
|class AnimalDecorator < ApplicationDecorator|