Skip to content

Instantly share code, notes, and snippets.

@artificemm
Created March 26, 2021 06:55
Show Gist options
  • Select an option

  • Save artificemm/fb162a744eefba1350c62c116f39ada1 to your computer and use it in GitHub Desktop.

Select an option

Save artificemm/fb162a744eefba1350c62c116f39ada1 to your computer and use it in GitHub Desktop.

Revisions

  1. artificemm created this gist Mar 26, 2021.
    11 changes: 11 additions & 0 deletions navigable.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    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