Skip to content

Instantly share code, notes, and snippets.

@fnhipster
Created December 20, 2010 00:08
Show Gist options
  • Save fnhipster/747856 to your computer and use it in GitHub Desktop.
Save fnhipster/747856 to your computer and use it in GitHub Desktop.
Get next record while it exists.
def some_method
self.find(:all, :order => "position DESC").each do |obj|
next_obj = self.find(:first, :conditions => ["position > ?", obj.position], :order => "position DESC")
# ...
break if next_obj == self.last
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment