Ruby/Rails-kaminari未定义方法分页错误 [英] Ruby/Rails - kaminari undefined method pagination errors

查看:71
本文介绍了Ruby/Rails-kaminari未定义方法分页错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不确定自己做了什么,但是kaminari开始在我的应用中表现怪异.

I'm not sure what I did, but kaminari has started acting weird in my app.

在我的控制器中:

@producers = Producer.order(:name).page(params[:page])

视图:

<%= paginate @producers %>

结果:

undefined method `num_pages' for #<ActiveRecord::Relation:0x000001026e6308>

如果我在控制器中添加.per:

If I add .per in my controller:

@producers = Producer.order(:name).page(params[:page]).per(25)

我知道

undefined local variable or method `per' for #<ActiveRecord::Relation:0x0000010928ef60>

最后,奇怪的是,如果我将.order(:name)移到末尾,它会起作用:

Finally, strangely, if I move my .order(:name) to the end, it works:

@producers = Producer.page(params[:page]).order(:name)

我猜我安装的其他gem的page范围或方法引起了问题?

I'm guessing some other gem I have installed has a page scope or method that's causing problems?

谢谢.

推荐答案

好了,就弄清楚了. 我安装了 Active Admin .它安装了will_paginate作为依赖项.

Well, just figured it out. I had Active Admin installed. It installed will_paginate as a dependency.

Active Admin的最新提交中,will_paginate已替换为kaminari.

In the latest commits for Active Admin, will_paginate has been replaced with kaminari.

我将我的Gemfile更改为从github中提取Active Admin. will_paginate已从我的捆绑包中删除,现在一切正常.您可以通过将以下行放入您的gemfile中来做到这一点:

I changed my Gemfile to pull Active Admin from github. will_paginate was removed from my bundle and now everything works. You can do this by putting the following line into your gemfile:

gem "activeadmin", git: "https://github.com/gregbell/active_admin"

这篇关于Ruby/Rails-kaminari未定义方法分页错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆