Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3: undefined method `page' for #<Array:0xafd0660>

I can't get past this. I know I've read there isn't a page method for arrays but what do I do?

If I run Class.all in the console, it returns #, but if I run Class.all.page(1), I get the above error.

Any ideas?

like image 396
Chris Bolton Avatar asked Aug 03 '11 23:08

Chris Bolton


2 Answers

No Array doesn't have a page method.

Looks like you are using kaminari. Class.all returns an array, thus you cannot call page on it. Instead, use Class.page(1) directly.

For normal arrays, kaminari has a great helper method:

Kaminari.paginate_array([1, 2, 3]).page(2).per(1) 
like image 188
James Chen Avatar answered Sep 20 '22 18:09

James Chen


Kaminari now has a method for paginating arrays, so you can do something like this in your controller:

myarray = Class.all @results = Kaminari.paginate_array(myarray).page(params[:page]) 
like image 34
DaveStephens Avatar answered Sep 19 '22 18:09

DaveStephens