When creating an application in rails API mode, I used a gem called Pagy for pagination. At that time, I was confused about how to write it, so I will leave it here as a memo.
pagy, offices = pagy_array([])
$ pagy, offices = pagy Office.where(city_id: params[:city_id])
pagy, offices = pagy(Office.all)
pagy_headers_merge(pagy)
If you add this below the above description, you can add pagination information to the HTTP header.
Recommended Posts