ruby-on-railsmongoidkaminari

pagination with kaminari and mongoid


I have this problem

undefined method `total_pages' for
# <Mongoid::Criteria:0x00000002651d80>

# controller
@services = Service.paginate(:page => params[:page], :per_page => 3)

# view
<% paginate @services %>

The mongo doesn't return the object.


Solution

  • In kaminari, you have to use below syntax

     Service.page(params[:page].to_i).per(3)
    

    instead of

     Service.paginate(:page => params[:page], :per_page => 3)
    

    This is the syntax of will_paginate