Kaminari undefined method `page' with Rails 4.2

两盒软妹~` 提交于 2019-12-08 03:53:09

问题


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

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


回答1:


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



回答2:


Have a look at this tutorial https://github.com/amatsuda/kaminari

This is how it works

 User.page(page_number).per(records_per_page)


来源:https://stackoverflow.com/questions/31729219/kaminari-undefined-method-page-with-rails-4-2

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