2

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 !

TW147
  • 561
  • 2
  • 7
  • 20

1 Answers1

6

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.

Dogbert
  • 212,659
  • 41
  • 396
  • 397
  • I get the same error. I tried `@products = Product.order("id").find_all_by_id(params[:id]).page(params[:page]) ` and `@products = Product.order("id").page(params[:page]).find_all_by_id(params[:id]) ` but it still don't work. – TW147 Jul 20 '11 at 16:44
  • Yes, but there is only one value in the array. It is not really clear, but my products are classified by categories and the `:id` is actually the category's id that the products in my list belongs to. If I do not put the pagination, I have the full list of my products in the category I've chosen before (`:id`). The problem is only when I set the pagination. – TW147 Jul 20 '11 at 17:12
  • Thanks @Dogbert you have cleared My concept, i am searching for this since long. A where condition for this works with pagination. – Ravindra Mar 25 '13 at 07:40