[RUBY] Implementation of pagination function

version

・ Ruby 2.5.7 ・ Rails 5.2.4.3

I want to display only 10 items per page using the pagination function

The image looks like this pagination_result

First install gem

To implement the pagination function, use the gem "kaminari". First, describe kaminari in the gemfile. After adding to the Gemfile, run bundle install in the terminal to install kaminari.

Then execute the following command

Execute the following to create the kaminari configuration file. If you move the numbers in this file, you can set how many items can be displayed per page. スクリーンショット 2020-08-08 22 31 08 You can modify the design of kaminari that is generated by executing the following. For details, this article was easy to understand. https://qiita.com/you8/items/df68aaee3010e282d1ae スクリーンショット 2020-08-08 22 37 13

Changed view and controller for pagination

To use kaminari, add the following to the view file you want to use. スクリーンショット 2020-08-08 22 41 41 The controller also got it with all, but modify it as follows. If you specify reverse_order, it will be displayed in the newest order. スクリーンショット 2020-08-08 22 52 35

Enter how many items you want to display in kaminari_config.rb in the config / initializers folder and you're done! !!

スクリーンショット 2020-08-08 22 55 08

Recommended Posts

Implementation of pagination function
Implementation of search function
Implementation of sequential search function
Implementation of like function (Ajax)
[Rails 6] Implementation of search function
Implementation of image preview function
[Rails] Implementation of category function
Implementation of category pull-down function
[Rails] Implementation of tutorial function
[Rails] Implementation of like function
[Rails 6] Pagination function implementation (kaminari)
[Rails] Implementation of CSV import function
[Rails] Asynchronous implementation of like function
Kaminari --Added pagination function of Rails
[Rails] About implementation of like function
[Rails] Implementation of user withdrawal function
[Rails] Implementation of CSV export function
Implementation of like function in Java
Pagination function (kaminari)
DM function implementation
Implementation of user authentication function using devise (2)
Implementation of user authentication function using devise (1)
Rails [For beginners] Implementation of comment function
[Rails 6] Implementation of SNS (Twitter) sharing function
[Vue.js] Implementation of menu function Implementation version rails6
[Ruby on rails] Implementation of like function
[Vue.js] Implementation of menu function Vue.js introduction rails6
[Rails] Implementation of search function using gem's ransack
Implementation of Ruby on Rails login function (Session)
[Rails 6] Implementation of inquiry function using Action Mailer
Implementation of flash messages
[Rails] Implementation of image enlargement function using lightbox2
Comment function (Ajax) implementation
Follow function (Ajax) implementation
[Rails] Implementation of retweet function in SNS application
Image preview function implementation
[JQuery] Implementation procedure of AutoComplete function [Java / Spring]
Applied implementation of chat-space
Rails search function implementation
Implementation of search function Learning memo (portfolio creation)
Search function [copype implementation]
Pagination implementation with gem'kaminari'
Implementation of delete function (if you have foreign_key)
Ruby on Rails <2021> Implementation of simple login function (form_with)
[Rails] Implementation of drag and drop function (with effect)
Implementation of Ruby on Rails login function (devise edition)
[Ruby on Rails] Implementation of tagging function/tag filtering function
[Rails] Implementation of multi-layer category function using ancestry "Preparation"
[Rails] Implementation of SNS authentication (Twitter, Facebook, Google) function
Addition of guest login function
Rails implementation of ajax removal
Use ransack Search function implementation
[Java] Implementation of Faistel Network
Implementation of XLPagerTabStrip with TabBarController
Implementation of unit test code
Implementation of gzip in java
Implementation of tri-tree in Java
Implementation of HashMap in kotlin
About merge processing implementation including sorting function of Stream API
[Rails] Implementation of multi-layer category function using ancestry "Editing form"
[Rails] Implementation of multi-layer category function using ancestry "Creation form"