undefined method page for #<Array:0xc347540> kaminari “page” error. rails_admin

回眸只為那壹抹淺笑 提交于 2019-12-08 20:57:33

You can not call Kaminari methods on Array, because Rule.all will return Array.

So you have to do something like this: Rule.page(1).per(2)

Here is documentation and examples of Kaminari usage:

https://github.com/amatsuda/kaminari

I've been running into this issue off and on for a while now using Mongoid. Sometimes refreshing the page in RailsAdmin would fix it.

I figured out that the problem is Kaminari's hooks are not initialized in my environment, so the models that rely on Kaminari's extension methods don't have them available.

I simply took the following line from Kaminari's railtie and put it at the top of my rails_admin initializer:

Kaminari::Hooks.init

Now things seem to be working for me. However, I don't know why the ActiveSupport callback is not running that code.

Use this

Kaminari.paginate_array(Rule.all).page(params[:page])

Kader's solution is great! The only thing is I found I have to add .per to make it work.

Kaminari.paginate_array(Rule.all).page(params[:page]).per(PER_PAGE_RECORDS)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!