I am a beginner who is currently working on a portfolio. It is a memorandum because I introduced kaminari and implemented the pagination function.
Gemfile
gem 'kaminari'
Terminal
% bundle install
events_controller.rb
def index
@events = Event.page(params[:page]).per(10)
end
A method called __page and per is a method defined in kaminari. You can specify how many records should be displayed in the argument of the per method to increase the page. __
ruby:events/index.html.erb
<%= paginate @events %>
__ Described in the view file you want to display. __
__that's all! __
Pagination displayed by kaminari cannot be css in the view. So the following method.
Terminal
% rails g kaminari:views default
Added kaminari to the __app/views folder. __ Since the html of the pagination part is described in the __ folder, change it there. __
If you are using a css framework such as bootstrap, the display and design may be corrupted. Specify the default part in the name of each framework. If you are using bootstrap4, use the following command.
Terminal
% rails g kaminari:views bootstrap4
__ If you run this command and create a view file, it will be optimized for each framework style without any editing. __
Since it is written in English by default, to change it to Japanese notation Create a file called kaminari_ja.yml in the config/locales folder and write the following code.
config/locales/kaminari_ja.yml
ja:
views:
pagination:
first: "«the first"
last: "last»"
previous: "‹Before"
next: "Next›"
truncate: "..."
https://pikawaka.com/rails/kaminari
Recommended Posts