Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mongoid pagination

I tried

@posts = Post.page(params[:page]).per_page(10)

and

@posts = Post.paginate(:page => 1, :per_page => 10)    

but neither method works

undefined method `page' for Post:Class

undefined method `paginate' for Post:Class

How do you do pagination with mongoid?

like image 229
Vyacheslav Loginov Avatar asked Dec 18 '11 01:12

Vyacheslav Loginov


People also ask

What is skip and limit in pagination?

MongoDB has an extremely straightforward way to implement pagination: using skip and limit operations on a cursor. skip(n) skips n items in a query, while limit(m) returns only the next m items starting from the n-th one.


1 Answers

You should use Kaminari https://github.com/amatsuda/kaminari

like image 100
Vyacheslav Loginov Avatar answered Sep 20 '22 07:09

Vyacheslav Loginov