Skip to content

Instantly share code, notes, and snippets.

@rgo
Created June 24, 2009 22:10
Show Gist options
  • Save rgo/135546 to your computer and use it in GitHub Desktop.
Save rgo/135546 to your computer and use it in GitHub Desktop.
next and previous record methods
# You need to call the next and previous records. Just put the following in your model.
# From http://snippets.dzone.com/posts/show/7163
def next
self.class.find :first,
:conditions => ["created_at > ? ",self.created_at],
:order => "created_at DESC"
end
def previous
self.class.find :first,
:conditions => ["created_at < ? ",self.created_at],
:order => "created_at DESC"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment