Mongoid pagination

后端 未结 8 567
無奈伤痛
無奈伤痛 2021-02-05 12:01

I tried

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

and

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


        
相关标签:
8条回答
  • 2021-02-05 12:56

    This works fine for me:

    @posts = Post.paginate(:page => 1, :limit => 10).desc(:_id)
    

    desc(:_id) is added so that latest posts could be listed first.

    0 讨论(0)
  • 2021-02-05 12:56

    A bit late, but for anyone else looking, I found 'will_paginate_mongoid'

    https://github.com/lucasas/will_paginate_mongoid

    Really straight forward and lets you simply do

    collection.skip(20).limit(10)
    
    0 讨论(0)
提交回复
热议问题