Draper を使用してビューを装飾し、ビューからいくつかのロジックを移動していますが、この質問に苦労しています - Bootstrap Pagination ( will_paginate
) で Draper をセットアップする方法は?
デフォルトでは、これがあります:
delegate_all
そして、Draperのドキュメントから、これを追加しようとしました:
delegate :current_page, :per_page, :offset, :total_entries, :total_pages
ただし、ビューでページネーションを呼び出すと、まだエラーが返されます。私のコントローラーは、次のように装飾とページネーションを定義します。
@matches = Match.all.paginate(:per_page => 10, :page => params[:page]).decorate
そして私の見解:
<%= will_paginate @matches, renderer: BootstrapPagination::Rails %>
アップデート:
class ApplicationDecorator < Draper::Decorator
def self.collection_decorator_class
PaginatingDecorator
end
end
class PaginatingDecorator < Draper::Decorator
# support for will_paginate
delegate :current_page, :total_entries, :total_pages, :per_page, :offset
end
class PlayerDecorator < ApplicationDecorator
delegate_all
decorates_association :matches
class MatchDecorator < ApplicationDecorator
delegate_all
decorates_association :players