0

I have been following this tutorial to get the leaderboard gem working and I've got all of the leaderboard gem aspect of it working, but I am struggling to get the Kaminari gem part of it working (the paginate gem).

At the moment in my controller I have this:

class LeaderboardController < ApplicationController
  before_action :query_options

  def show
    @lb = Boards.default_leaderboard
    @entries = entry_service.execute(query_options)
    respond_to do |format|
      format.html do
        paginate
      end
      format.json do
        render json: @entries
      end
    end
  end

  private

def query_options
    @limit = [params.fetch(:limit, 10).to_i, 100].min
    @page = params.fetch(:page, 1).to_i
    { page: @page, limit: @limit }
  end

  def paginate
    pager = Kaminari.paginate_array(
      @entries,
      total_count: @lb.total_members)

    @page_array = pager.page(@page).per(@limit)
  end

And in the views I have:

= paginate @page_array

But for some reason this is not paginating the @entries...

camillavk
  • 521
  • 5
  • 20

1 Answers1

0

For the way you have it set up you need to call the before_action :paginate.

Zippo9
  • 706
  • 2
  • 5
  • 24
  • when i do that it can't find the leaderboard and responds with `undefined method 'total_members' for NilClass`.... – camillavk May 08 '15 at 17:22