Created
October 26, 2013 06:02
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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