I wanted to retrieve a users rank in a highscore leaderboard for a game.

Heres the simple way to get the rank.

# Method 1: Quick & Dirty

# Method 2: Much more efficient by only getting required column

# Method 3: Fastest Method
User.where("score <= ?", current_highscore).count

If anyone has a less expensive way of performing this operation I would love to hear about it.

Related External Links: