echan00
echan00

Reputation: 2807

Using limit and offset in addition to pagination

I would like to offset my records and then limit the total number of records that will be queried with something similar to the below.

Would anybody have suggestions how to go about it?

@document_texts = Texts.where(active: true).reorder(created_at: :asc).limit(x).offset(y).page(params[:page])

Upvotes: 1

Views: 1475

Answers (1)

Salil
Salil

Reputation: 47522

Use page & per for the kaminari gem

@document_texts = Texts.where(active: true).reorder(created_at: :asc)
                       .page(params[:page]).per(50)

When params[:page] = 2 it will fetch records from 51 to 100.

Upvotes: 1

Related Questions