2012-12-14 35 views
0

我在控制台中输入这个检索的记录:will_paginate不工作与find

user.bookmarks.page(1) 

-> ok 

Bookmark.find([21, 23]).page(1) 

-> undefined method `page' for #<Array:0x5b2b3a0> 

使用PAGINATE方法也试过:Bookmark.find([21, 23]).paginate(page: "1"),具有相同的结果。

任何想法在这里出了什么问题?

+1

如果您使用find,这意味着您确切地知道您期望的是什么,这就是为什么一个(不可链接的)数组被检索到 – apneadiving

+0

不是'user.bookmarks'也是数组? ('user.bookmarks.class => Array') – mihai

回答

2

也许这:

Bookmark.paginate(:conditions => {:id => [21,23]}, :page => 1) 

或简单化:

Bookmark.where(:id => [21,31]).page(1) 
+0

很酷,这对我有用,谢谢。我仍然困惑,为什么它不适用于查找。 – mihai

+0

@apneadiving在评论中回答说。试试这个,它可能会使它更清晰:Bookmark.find([21,23]).class和Bookmark.where(:id => [21,32])。类 –

+0

k,显示一个'ActiveRecord :: Relation' ,但'user.bookmarks.class'显示一个数组。哦,奇怪的东西,但我不会进一步深入这一点。 – mihai

1

如果您使用的轨道3或以上,will_paginate /阵列需要在配置显式加载/ application.rb中进行分页阵列(with Bookmark.find或Bookmark.all)