Skip to content

Instantly share code, notes, and snippets.

@hfujimoto
Created October 26, 2013 06:02
Show Gist options
  • Select an option

  • Save hfujimoto/7165807 to your computer and use it in GitHub Desktop.

Select an option

Save hfujimoto/7165807 to your computer and use it in GitHub Desktop.
File at the app/models/concerns directory for Ruby On Rails. Find out previous and next resource of the collection
module CommonNext
extend ActiveSupport::Concern
def previous_record
self.class.unscoped.where('id < ?', self.id).order(:id).last
end
# Find Next Record Method
def next_record
self.class.unscoped.where('id > ?', self.id).order(:id).first
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment