Created
April 7, 2014 05:34
-
-
Save JunichiIto/10015280 to your computer and use it in GitHub Desktop.
Sample code to find next/prev user by date_of_birth.
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
user = User.find params[:id] | |
older_user = User.where("date_of_birth <= ? AND id <> ?", user.date_of_birth, user.id).order("date_of_birth DESC, id").limit(1).first | |
younger_user = User.where("date_of_birth >= ? AND id <> ?", user.date_of_birth, user.id).order("date_of_birth ASC, id").limit(1).first |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment