diff --git a/Gemfile b/Gemfile index c5bccc8..729f8cf 100644 --- a/Gemfile +++ b/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 diff --git a/Gemfile.lock b/Gemfile.lock index 79d408e..eb8b358 100644 --- a/Gemfile.lock +++ b/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) diff --git a/app/controllers/blog_posts_controller.rb b/app/controllers/blog_posts_controller.rb index 90d4dd7..532b419 100644 --- a/app/controllers/blog_posts_controller.rb +++ b/app/controllers/blog_posts_controller.rb @@ -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 diff --git a/app/controllers/microposts_controller.rb b/app/controllers/microposts_controller.rb index be05e3a..2e4a373 100644 --- a/app/controllers/microposts_controller.rb +++ b/app/controllers/microposts_controller.rb @@ -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 diff --git a/app/models/blog_post.rb b/app/models/blog_post.rb index 08fa270..58802cb 100644 --- a/app/models/blog_post.rb +++ b/app/models/blog_post.rb @@ -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 diff --git a/app/views/blog_posts/index.html.erb b/app/views/blog_posts/index.html.erb index 5247cad..276505c 100644 --- a/app/views/blog_posts/index.html.erb +++ b/app/views/blog_posts/index.html.erb @@ -10,4 +10,5 @@
  • <%= render blog_post %>
  • <% end %> + <%= paginate @blog_posts %> <% end %> diff --git a/app/views/microposts/index.html.erb b/app/views/microposts/index.html.erb index f317add..b6ddbe3 100644 --- a/app/views/microposts/index.html.erb +++ b/app/views/microposts/index.html.erb @@ -12,4 +12,5 @@
  • <%= render micropost %>
  • <% end %> + <%= paginate @microposts %> <% end %>