First pagination feature added in rails

First pagination feature added in rails

Referenced article (https://qiita.com/residenti/items/1ae1e5ceb59c0729c0b9)

What is pagination?

It is to read the information by dividing the lengthened content into multiple pages. For example, google search results.

First gem install

It is implemented using a gem called kaminari.

gemfile


gem'kaminari', '~> 0.17.0'

In rails5 series, it seems that it will not work unless the version of kaminari is specified as above. bundle install.

controller

topics_controller


 @topics=Topic.page(params[:page]).per(5)

@topics=Topic.all Has been changed as above. Use the per method to determine how many items are displayed on one page.

View

ruby:index.html.erb


 <% @topics.each do |a| %>
problem:<%=a.question %><br><br>
              1:<%=a.choice1 %><br>
              2:<%=a.choice2 %><br>
              3:<%=a.choice3 %><br>
              4:<%=a.choice4 %><br>
 <% end %>

<%= paginate @topics %>

Just write <% = paginate @topics%>. This completes the addition of the pagination function.

Recommended Posts

First pagination feature added in rails
Kaminari --Added pagination function of Rails
[Rails] Favorite feature
Implement Rails pagination
Group_by in Rails
How to implement a like feature in Rails
Implement the Like feature in Ajax with Rails.
[Rails] Added in devise: username not added to database
Use pagy for pagination in your Rails app.
[Rails] Ranking and pagination in order of likes
How to implement a like feature in Ajax in Rails
Model association in Rails
Adding columns in Rails
About rails kaminari pagination
Disable turbolinks in Rails
^, $ in Rails regular expression
Use images in Rails
Understand migration in rails
Questions about implementing the Like feature (Ajax) in Rails
Split routes.rb in Rails6
Do not write 〇〇 logic in Rails View (* added later)
Implement markdown in Rails
Get UserAgent in [Rails] controller
Implement application function in Rails
Declarative transaction in Rails #ginzarb
Implement follow function in Rails
Japaneseize using i18n with Rails
Gem often used in Rails
Display Flash messages in Rails
Rails reference type creation added
View monthly calendar in Rails
Implement import process in Rails
First Java development in Eclipse
Use multiple checkboxes in Rails6!
Rewrite Routes in Rails Engine
[Rails 6] Pagination function implementation (kaminari)