Skip to content

Instantly share code, notes, and snippets.

@artificemm
Created March 26, 2021 06:55
Show Gist options
  • Save artificemm/fb162a744eefba1350c62c116f39ada1 to your computer and use it in GitHub Desktop.
Save artificemm/fb162a744eefba1350c62c116f39ada1 to your computer and use it in GitHub Desktop.
Nice navigation between records module
module Navigable
extend ActiveSupport::Concern
def next
self.class.where("id > ?", self.id).order(id: :asc).first
end
def previous
self.class.where("id < ?", self.id).order(id: :desc).first
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment