本文介绍了Kaminari 未定义的方法“页面"与 Rails 4.2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Kaminari 0.16.3Rails 4.2.0.不知道出了什么问题,我在控制台中粘贴了我运行的代码,这证明 kaminari gem 已加载但 page 方法未在 ActiveRecord 模型.

I am using Kaminari 0.16.3 with Rails 4.2.0. Not sure what is going wrong, I have pasted code run by me in console, which proves kaminari gem is loaded but page method is undefined on ActiveRecord model.

abhishek@abhishek ~/my_app (master●●)$ rails c                                                                     [ruby-2.1.5p273]
Loading development environment (Rails 4.2.0)
irb(main):001:0> Kaminari
=> Kaminari
irb(main):002:0> User.page
NoMethodError: undefined method `page' for User (call 'User.connection' to establish a connection):Class

请注意:我有意在没有任何参数的情况下调用 page 来重现该问题.

Please note: I am intentionally calling page without any arguments to reproduce the issue.

推荐答案

由于 will_paginaterails_admin 的问题,我的代码库中有这个问题导致 要重命名为 per_page_kaminari 的页面 方法.

Due to an issue with will_paginate and rails_admin I had this in my codebase causing the page method to be renamed to per_page_kaminari.

我意识到这一点很晚并修复了.

I have realized this late and fixed.

Kaminari.configure do |config|
  config.page_method_name = :per_page_kaminari
end

这篇关于Kaminari 未定义的方法“页面"与 Rails 4.2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-25 18:01