LoginSignup
1
1

More than 5 years have passed since last update.

ページャの実装(kanimari)

Last updated at Posted at 2018-04-10

kaminariによる実装

gemを入れる

Gemfile
  gem 'kaminari'

その後$ bundle installを実行

ファイルの生成

$ rails generate kaminari:views defaultを実行し、ファイルを生成

ファイルに書き込む

  1. controllerでインスタンス変数に格納する
controller
  def index
      @pages = Page.page(params[:page])
  end
  1. viewにページネーションを表示
views
  <%= @pages.each do |f| %>
    .
    .
    .
  <% end %>

  #ここを記述
  <%= paginate @pages, class: "paginate"  %>

 カスタマイズ

一覧の表示数の変更

config/initializers/kaminari_config.rb
  Kaminari.configure do |config|
      config.default_per_page = 5
  end
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1