Rails 3:#< Array:0xafd0660>的未定义方法`page' [英] Rails 3: undefined method `page' for #<Array:0xafd0660>
本文介绍了Rails 3:#< Array:0xafd0660>的未定义方法`page'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我无法超越.我知道我已经读过数组的分页方法,但是我该怎么办?
I can't get past this. I know I've read there isn't a page method for arrays but what do I do?
如果我在控制台中运行Class.all,它将返回#,但是如果我运行Class.all.page(1),则会出现上述错误.
If I run Class.all in the console, it returns #, but if I run Class.all.page(1), I get the above error.
有什么想法吗?
推荐答案
没有数组没有分页方法.
No Array doesn't have a page method.
好像您正在使用kaminari. Class.all返回一个数组,因此您不能在其上调用页面.而是直接使用Class.page(1).
Looks like you are using kaminari. Class.all returns an array, thus you cannot call page on it. Instead, use Class.page(1) directly.
对于普通数组,kaminari有一个很好的帮助方法:
For normal arrays, kaminari has a great helper method:
Kaminari.paginate_array([1, 2, 3]).page(2).per(1)
这篇关于Rails 3:#< Array:0xafd0660>的未定义方法`page'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文