From 65808633a2e0259b54cefb268ebf79418b49e67c Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Sun, 5 Nov 2023 20:32:13 -0500 Subject: Added forward and back links to blog posts --- app/models/blog.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'app/models/blog.rb') diff --git a/app/models/blog.rb b/app/models/blog.rb index 03643bf..8599bcd 100644 --- a/app/models/blog.rb +++ b/app/models/blog.rb @@ -48,6 +48,14 @@ class Blog < ApplicationRecord end end + def prev + Blog.where(published: true).where("published_at < ?", published_at).order(published_at: :desc).first + end + + def next + Blog.where(published: true).where("published_at > ?", published_at).order(published_at: :asc).first + end + private def set_draft_title if self.title.blank? and not self.published -- cgit 1.4.1