0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【Rails】【メモ】Kaminariの使い方

Posted at

環境

  • Mac(12.2.1)
    • MacBook Pro (13-inch, 2020)
    • 2 GHz クアッドコアIntel Core i5
    • 16 GB 3733 MHz LPDDR4X
  • ruby (3.0.0p0)
  • rails (7.0.1)
  • mysql2 (0.5.3)

内容

通常は

egograms_controller.rb
@index=EgoScore.page(params[:page]).per(3)

のようにpageメソッドをしようするだけでページネーションをつくることができる

findやwhereを使用している場合はKaminari.paginate_arrayを使用

egograms_controller.rb
@index=Kaminari.paginate_array(index).page(params[:page]).per(2)
egograms/index.erb
# 表示したいviewに追記
 <%= paginate @index %>
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?