1
0

More than 3 years have passed since last update.

[Ruby on rails]検索結果でもページネーション使う kaminari

Posted at

初めに

過去の検索機能実装の記事はこちら。

ページネーション導入済みで、一覧画面では使用してましたが、
検索結果では使わず、全表示にしていました・・・。
なので、今回検索結果の表示画面でもページネーションを使用していきたいと思います。

コントローラー

class Users::SearchesController < ApplicationController
  def index
  users= User.search(params[:keyword])
  @users=users.page(params[:page]).per(25)
  end

end

これでほぼOKです!

VIEW 検索結果表示画面

       <div class="pagination pagination-sm justify-content-center">
       <%= paginate @users %></div

以上で、完了です。

1
0
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
0