It is one of the ruby gems and is for making page nations.
Add the following to Gemfile
.
gem 'kaminari'
Install in the terminal.
$ bundle install
class PostsController < ApplicationController
def index
@posts = Post.all
@posts = Post.page(params[:page]).per(15)
end
end
Set how many to display per page in the part of page (params [: page]). per (15)
.
Pagination is displayed when the number displayed is greater than the set number.
Add it where you want the pagenation to appear in the view.
<%= paginate @posts %>
The default display of kaminari is English.
For Japanese localization, it is easier to manage by creating a file called kaminari_ja.yml
in config/locales
.
Add the following to kaminari_ja.yml
.
ja:
views:
pagination:
first: "«the first"
last: "last»"
previous: "‹Before"
next: "Next›"
truncate: "..."
helpers:
page_entries_info:
one_page:
display_entries:
zero: ""
one: "<strong>1-1</strong>/1 case"
other: "<strong>1-%{count}</strong>/%{count}In case"
more_pages:
display_entries: "<strong>%{first}-%{last}</strong>/%{total}In case"
Recommended Posts