[RUBY] How to write to apply gem Pagy (pagination) to an array

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.

Description to apply to the array

pagy, offices = pagy_array([])

How to apply normally

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

Description of HTTP header

pagy_headers_merge(pagy)

If you add this below the above description, you can add pagination information to the HTTP header.

Recommended Posts

How to write to apply gem Pagy (pagination) to an array
How to write an RSpec controller test
How to write an if statement to improve readability-java
How to use an array for HashMap keys
How to create pagination for a "kaminari" array
How to write Rails
How to write dockerfile
How to write docker-compose
How to write Mockito
How to write migrationfile
How to use an array for a TreeMap key
How to output standard from an array with forEach
How to write an external reference key in FactoryBot
How to create an application
How to write good code
Bit Tetris (how to write)
[Refactoring] How to write routing
Great poor (how to write)
[Note] How to write Dockerfile/docker-compose.yml
How to write Junit 5 organized
How to write Rails validation
How to write Rails seed
[Ruby] How to write blocks
How to handle an instance
How to write Rails routing
How to initialize Java array
How to change a string in an array to a number in Ruby
How to retrieve the hash value in an array in Ruby
How to write query option when using gem ruby-firebase (memorial)
[Ruby] How to batch convert strings in an array to numbers
[Rails] How to use gem "devise"
[Ruby] How to count even or odd numbers in an array
[Rails] How to write in Japanese
[Swift5] How to get an array and the complement of arrays
Baseball ball count (how to write)
How to output the value when there is an array in the array
How to insert an external library
How to write a ternary operator
Rails on Tiles (how to write)
[Rails] How to write exception handling?
How to write Java variable declaration
Y-shaped road tour (how to write)
How to write easy-to-understand code [Summary 3]
[RSpec] How to write test code
How to make a Java array
[Swift] Summary of how to remove elements from an array (personal note)
[Java] How to turn a two-dimensional array with an extended for statement
How to convert an array of Strings to an array of objects with the Stream API
How to crop an image with libGDX
How to blur an image (super easy)
Summary of how to write annotation arguments
How to publish an application on Heroku
How to add a new hash / array
[Introduction to Java] How to write a Java program
[Java] How to output and write files!
How to define an inner class bean
Convert an array of strings to numbers
How to write Spring AOP pointcut specifier
[SpringBoot] How to write a controller test
How to write and explain Dockerfile, docker-compose
[Note] [Beginner] How to write when changing the value of an array element in a Ruby iterative statement