0
votes

Is there a way to put more items on the first page than the rest of the pages, when using pagination in Rails?

I am using the Kaminari gem to paginate a list of items and have implemented infinite scroll to browse through the pages. I want to limit the number of listings loaded per page when scrolling, but would like the initial page to start with a significant amount. Below is the current call to Kaminari in my listings controller:

@listings = Listing.page(params[:page]).per(25)
2
The easiest way to do that might just be to write some JS to trigger loading the second page of results right away -- that way you don't need to do wacky math or logic on the server side. - muffinista

2 Answers

0
votes

Something like this?

@listings = Listing.page(params[:page]).per(params[:page].to_i == 1 ? 100 : 25)
0
votes

I solved the problem like this (First page items is supposed 2 items and next pages 7 items):

per_page = 7 @comments = @content.comments.page(params[:page]).per(per_page).padding((per_page-2) * -1)