Created
June 24, 2009 22:10
-
-
Save rgo/135546 to your computer and use it in GitHub Desktop.
next and previous record methods
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
# 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