Skip to content

Instantly share code, notes, and snippets.

@kevinluo201
Created October 2, 2018 17:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevinluo201/df5e373e667ee7d19dbcd1038bb78e87 to your computer and use it in GitHub Desktop.
Save kevinluo201/df5e373e667ee7d19dbcd1038bb78e87 to your computer and use it in GitHub Desktop.
next, prev
class User
has_many :photos
end
class Photo
belongs_to :user
def next
user.photos.where("id > ?", id).first
end
def prev
user.photos.where("id < ?", id).last
end
end
Now you can:
photo.next
photo.prev
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment