Referenced article (https://qiita.com/residenti/items/1ae1e5ceb59c0729c0b9)
It is to read the information by dividing the lengthened content into multiple pages. For example, google search results.
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.
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