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