Use kaminari for pagination
This commit is contained in:
parent
de4eb6742b
commit
01bcdf3a2d
2
Gemfile
2
Gemfile
|
@ -14,6 +14,8 @@ gem "jbuilder"
|
|||
gem "bcrypt", "~> 3.1.7"
|
||||
gem "bootsnap", require: false
|
||||
|
||||
gem "kaminari" # Pagination
|
||||
|
||||
group :development, :test do
|
||||
gem "debug", platforms: %i[ mri mingw x64_mingw ]
|
||||
end
|
||||
|
|
13
Gemfile.lock
13
Gemfile.lock
|
@ -129,6 +129,18 @@ GEM
|
|||
sshkit (~> 1.21)
|
||||
thor (~> 1.2)
|
||||
zeitwerk (~> 2.5)
|
||||
kaminari (1.2.2)
|
||||
activesupport (>= 4.1.0)
|
||||
kaminari-actionview (= 1.2.2)
|
||||
kaminari-activerecord (= 1.2.2)
|
||||
kaminari-core (= 1.2.2)
|
||||
kaminari-actionview (1.2.2)
|
||||
actionview
|
||||
kaminari-core (= 1.2.2)
|
||||
kaminari-activerecord (1.2.2)
|
||||
activerecord
|
||||
kaminari-core (= 1.2.2)
|
||||
kaminari-core (1.2.2)
|
||||
loofah (2.21.4)
|
||||
crass (~> 1.0.2)
|
||||
nokogiri (>= 1.12.0)
|
||||
|
@ -264,6 +276,7 @@ DEPENDENCIES
|
|||
importmap-rails
|
||||
jbuilder
|
||||
kamal
|
||||
kaminari
|
||||
pg
|
||||
puma
|
||||
rails (~> 7.1)
|
||||
|
|
|
@ -5,7 +5,9 @@ class BlogPostsController < ApplicationController
|
|||
before_action :set_blog_post, only: [:show, :edit, :update, :destroy]
|
||||
|
||||
def index
|
||||
@blog_posts = BlogPost.published.order(created_at: :desc)
|
||||
@blog_posts = BlogPost.published
|
||||
.order(created_at: :desc)
|
||||
.page(params[:page])
|
||||
end
|
||||
|
||||
def new
|
||||
|
|
|
@ -5,7 +5,9 @@ class MicropostsController < ApplicationController
|
|||
before_action :set_micropost, only: [:show, :edit, :update, :destroy]
|
||||
|
||||
def index
|
||||
@microposts = Micropost.all.order(created_at: :desc)
|
||||
@microposts = Micropost.all
|
||||
.order(created_at: :desc)
|
||||
.page(params[:page])
|
||||
end
|
||||
|
||||
def new
|
||||
|
|
|
@ -18,6 +18,8 @@ class BlogPost < ApplicationRecord
|
|||
scope :published, -> { where(published: true) }
|
||||
scope :draft, -> { where(published: false) }
|
||||
|
||||
paginates_per 15
|
||||
|
||||
def to_param
|
||||
slug
|
||||
end
|
||||
|
|
|
@ -10,4 +10,5 @@
|
|||
<li><%= render blog_post %></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
<%= paginate @blog_posts %>
|
||||
<% end %>
|
||||
|
|
|
@ -12,4 +12,5 @@
|
|||
<li><%= render micropost %></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
<%= paginate @microposts %>
|
||||
<% end %>
|
||||
|
|
Loading…
Reference in New Issue