3

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
4

1 に答える 1

7

https://github.com/drapergem/draper/issues/429

# app/decorators/application_decorator.rb
class ApplicationDecorator < Draper::Decorator
  def self.collection_decorator_class
    PaginatingDecorator
  end
end

# app/decorators/paginating_decorator.rb
class PaginatingDecorator < Draper::CollectionDecorator
  # support for will_paginate
  delegate :current_page, :total_entries, :total_pages, :per_page, :offset
end

# app/decorators/whatever_decorator.rb
class WhateverDecorator < ApplicationDecorator
end
于 2015-05-07T09:58:04.030 に答える