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 5 years have passed since last update.

slimでkaminari導入

0
Last updated at Posted at 2020-03-02

ERBで導入経験はありましたが、slimではなかったので、試しました。

まずはgem追加

Gemfile
gem 'kaminari'
command
bundle

コントローラ側とviewを修正していきます。

hoges_controller
def index
  @hoges = Hoge.page(params[:page])
end
hoges/index.html.slim
.mb-3
  = paginate @hoges

下記のように表示できれば成功です!

スクリーンショット 2020-03-03 7.54.02.png

デフォルト設定が25レコードなので、それ以上データが無いと表示されませんでした。追加してから動作確認した方が良さそうです。

ちなみに、下記のように.per(8)を追加すれば表示したいレコードを
指定できるので、わざわざ25も登録しなくても確認できます。

hoges_controller
def index
  @hoges = Hoge.page(params[:page]).per(8)
end

参考

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?