Search code examples
ruby-on-railsexceptionpaginationkaminari

Error with Kaminari pagination


I would like to paginate my objects with the Kaminari pagination gem. I have this line in my controller:

@products = Product.order("id").find_all_by_id(params[:id])

That line in my view:

<%= paginate @products %>

And that line in my model:

paginates_per 20

When I open my page where my objects are supposed to be listed, I have this error message :

undefined method `current_page' for #<Array:0x2964690>

The exception is raised at my <%= paginate @products %> line.

I have already made a pagination for another project and it was working really great. Could someone help me please ?

Thank you !


Solution

  • Edit:

    The problem is that find_all_by_* returns an array, not an ActiveRecord::Relation.

    You can do something like this instead

    @products = Product.order("id").where("id IN (?)", params[:id])
    

    Also, you should probably have a .page(params[:page]) in there.