Rails 3 在 mongoid 嵌入文档上使用 kaminari 进行分页
当我在嵌入文档集合上使用 kaminari 调用 paginate 时,出现以下错误:
(Access to the collection for Document is not allowed since it is an embedded document, please access a collection from the root document.):
知道如何解决这个问题吗?我已经将 kaminari 作为 gem 安装了。
亚历克斯
When I call paginate with kaminari on a collection of embedded documents I get the following error:
(Access to the collection for Document is not allowed since it is an embedded document, please access a collection from the root document.):
Any idea on how I can fix that ? I have installed kaminari as a gem.
Alex
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您只需要通过父对象访问集合即可。例如,给定以下模型:
然后要对给定用户的书签进行分页,您可以执行以下操作:
You just need to access the collection through the parent object. For example, given the following models:
Then to paginate a given user's bookmarks you would do:
我在 Kaminari 上发现了这个问题: https://github.com/amatsuda/kaminari/issues/89< /a>
所以我分叉了它,并按照 spatrik 提供的解决方案修复了它。我不能 100% 确定它适用于所有情况,并且该解决方案没有任何缺点。但目前它的工作原理与预期完全一致。
亚历克斯
I found this issue on Kaminari: https://github.com/amatsuda/kaminari/issues/89
So I forked it, and fixed it following the solution provided by spatrik. I am not 100% sure it will work on all cases and that this solution does not have any drawbacks. But for the moment it works exactly as expected.
Alex
我刚刚针对该问题发送了一个补丁。看看请求。希望这有助于解决您的问题。
https://github.com/amatsuda/kaminari/pull/155/files
I just sent a patch for the issue. Take a look at the request. hope this helps solve your issue.
https://github.com/amatsuda/kaminari/pull/155/files
对于前面的 theTRON 示例:
下面的示例将给您带来您在帖子中描述的错误:
而下一个示例将正常工作:
我希望它有所帮助。
With the previous theTRON example :
the following, will get you the error you described in your post :
while the nex one will works fine :
I hope it help.