Created
September 10, 2014 15:51
-
-
Save b-murphy/34c820619b291d2dee32 to your computer and use it in GitHub Desktop.
This file contains 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
def self.find_or_next(id) | |
find(id) | |
rescue ActiveRecord::RecordNotFound | |
if (id == last.id + 1) then raise ActiveRecord::RecordNotFound; end | |
find(id+1) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm not sure why you want this but I think you should use
find_by(id: id)
to prevent theRecordNotFound
being raised.