简体   繁体   中英

Rails: Filterrific and Kaminari not loading objects after page 1

I'm using Rails, Filterrific, and Kaminari for pagination. For some reason, when I go to page 2, I get no results.

def index
@user = User.new
  @filterrific = initialize_filterrific(
  Trailer,
  params[:filterrific],
  select_options: {
    sorted_by: Trailer.options_for_sorted_by
  }
) or return
trailers = @filterrific.find.page(params[:page])
@trailers = Kaminari.paginate_array(trailers).page(params[:page]).per(30)
binding.pry
end

I pried into the action and saw that, when first loading the page.. trailers.count == 200, params[:page] == nil, and @trailers.count == 30.

When I go to page 2, trailers.count == 200, params[:page] == "2", and @trailers.count == 0.

Am I doing something wrong in the way I'm calling Kaminari or something?

Okay so I ended up changing this line:

trailers = @filterrific.find.page(params[:page])
@trailers = Kaminari.paginate_array(trailers).page(params[:page]).per(30)

to this:

@trailers = @filterrific.find.page(params[:page])

And also had an issue with will_paginate conflicting with Kaminari so I removed w_p

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM