How To Get A Records Rank In Rails

Posted by Weston Ganger on November 23, 2015

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:

Posted in Rails and Tagged with rails active-record 

Want me to help develop your next project or application?

Contact Us

Specializing in Ruby-on-Rails, Javascript, Multi-Platform Electron Desktop Apps and Hybrid Cordova Mobile Apps.

Recommended Posts