Rails: Filterrific and Kaminari not loading objects after page 1

263 views Asked by At

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?

1

There are 1 answers

0
Jackson Cunningham On

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