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.
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
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