[RAILS] I got a little more familiar with kaminari. Use kaminari_themes, generate config file

What did you do

It's a gem that I've used many times, but I haven't read the readme well. I tried to implement kaminari a little more carefully while reading the Official Document.

In particular, --Generate a config file --Using kaminari_themes

I did. The kaminari implementation itself is not deeply involved.

Generation of configuration file kaminari_config.rb

I used to draw the number of kaminari displayed like this all the time.

@posts = Post.page(params[:page]).per(15)

As I looked at the various codes, I realized that there was likely to be a configuration file, so I looked it up. Then, I found Official description here.

python


rails g kaminari:config

↑ This command will generate a file called kaminari_config.rb under config/initializers/. (It seems that you do not have to use the generate command to generate similar files.)

By default, the configuration file contains the following contents.

config/initializers/kaminari_config.rb


Kaminari.configure do |config|
  # config.default_per_page = 25
  # config.max_per_page = nil
  # config.window = 4
  # config.outer_window = 0
  # config.left = 0
  # config.right = 0
  # config.page_method_name = :page
  # config.param_name = :page
  # config.max_pages = nil
  # config.params_on_first_page = false
end

It seems that you have all the options you use often. Default_per_page in this

python


config.default_per_page = 10

If you set it to, the number of displayed items can be adjusted by default.

About the change of appearance

Regarding the appearance, it seems that it can be set with the following command.

$ rails g kaminari:views theme name

In this "theme name" part, there is a library in Page different from gem kaminari, and it seems that you can select from there.

This time I wanted to apply the theme with Bootstrap4 & slim, so I ran this command.

$ rails g kaminari:views bootstrap4 -e slim

Here is the actual file. Image from Gyazo

Impressions, etc.

I would like to investigate and make the pagenate array that I saw at work and the ** ajax pagenation that I created before but died.

Recommended Posts

I got a little more familiar with kaminari. Use kaminari_themes, generate config file
I tried playing with BottomNavigationView a little ①
I want to use a little icon in Rails
I want to monitor a specific file with WatchService
I tried OCR processing a PDF file with Java
I got an ActionController :: MissingExactTemplate even though I have a file
I tried OCR processing a PDF file with Java part2