1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【Ruby on Rails】gem Pagy(ページネーション)を配列に適用させる書き方

Last updated at Posted at 2020-09-25

railsのAPIモードでアプリケーションを作る際、ページネーションでPagyというgemを使用しました。
その際、記述の仕方に迷ったのでメモとしてここに残しておきます。

配列に適用させる記述

pagy, offices = pagy_array([])

ふつうに適用させる方法

$ pagy, offices = pagy Office.where(city_id: params[:city_id])
pagy, offices = pagy(Office.all)

HTTPヘッダーに関する記述

pagy_headers_merge(pagy)

これを上の記述の下に追記すると、HTTPヘッダーにページネーションの情報を持たせることができる。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?