I have a problem. I successfully implemented the Kaminari pagination using the following code in my controller:
def index
users = User.order(:creation_date).reverse_order.page(params[:page])
# Filter users
users = users.where(gender: params[:gender]) if params[:gender]
users = users.where(job: params[:job]) if params[:job]
users = users.where(car: params[:car]) if params[:car]
@users = users
end
But now I added a class which modifies some data parts in the user. This method returns the same users list, but with the modified data, but after that, I get this error in my webapp:
undefined method `total_pages'
I understand that this new returned list isn't a kaminari data list, because it lost the page
method that I put on it in the first query, but when I try to put it on the new list, I get this:
undefined method `page'
This line is added after the filters in the controller:
users = Scanner::Origin.calculate(users)
So I have tried adding users = users.page(params[:page]).per(20)
below the new line, but that doesn't work.
Any ideas how to fix the pagination with this new data?
CodePudding user response:
Try using
def index
users = User.order(creation_date: :desc).page(params[:page])
...