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
...
对于设置方法,您需要调用before_action:paginate。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.