My application has a user model with two integer columns, :votes and :badges, in addition to the usual :id and :timestamp columns.
Currently, the default scope for users is:
default_scope order: 'users.created_at DESC'
How can I update the default scope to order by a ranking algorithm made up of :votes :badges?
My algorithm is:
ranking = 2 * votes + badges
What is the best way to do this?
I expected to be able to create a method in the model as follows, but this doesn’t work
def ranking
2 * self.votes + self.badges
end
Do I need to create a ranking column in my database?
Thanks very much for your help!
You should be able to write