Rails3 Kaminari 未定义 .all
你好 我想知道如何解决分页宝石“Kaminari”遇到的问题。
据我了解,您无法对 @user = User.all.page(5) 进行分页?
但是,如果我有这段代码并想要对其进行分页,是否可能或者我是否需要更改代码?
@price = Price.joins(:retailer, :retailer => :profile).
where(['product_id=? AND size_id=?', params[:prod_id], params[:si_id]]).
group(:retailer_id).order("SUM((prices.price * #{params[:amount].to_i}) + profiles.shippingCost)").all
当将.page(5)应用于该代码时,我现在收到的唯一的东西是
undefined method `page' for #<Class:0x000001023c4558>
Hi
I wonder how to work around the problem I have with the pagination gem "Kaminari".
For what I've understood you cant paginate @user = User.all.page(5)?
But what if I have this code and want to paginate that, is it possible or do I need to change the code?
@price = Price.joins(:retailer, :retailer => :profile).
where(['product_id=? AND size_id=?', params[:prod_id], params[:si_id]]).
group(:retailer_id).order("SUM((prices.price * #{params[:amount].to_i}) + profiles.shippingCost)").all
The only thing I receive right now when applying.page(5) to that code is
undefined method `page' for #<Class:0x000001023c4558>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不需要
.all
因为 join 调用以及 where 和 group 正在为您返回符合您条件的对象数组。删除实例变量上的 .all 和调用页面(您可能希望将其重命名为@pages
或其他复数形式)。You don't need the
.all
because the joins call, along with where and group, is returning an array of objects for you that meet your criteria. Remove your .all and call page on the instance variable (which you might want to rename to@pages
or something else plural).