This is a follow-up question to Custom, Efficient, Complex Ordering in Rails 3
I’d like to develop an efficient ordering method for a rails model I have. Suppose that I save a rating for all objects in a field named “popularity”. If I wanted to sort by this rating I would do:
Model.order('popularity ASC')
How would I order by a skew for created at? Is there a way to, perhaps, convert the creation timestamp to an integer value, and then sort by popularity – created_at such that older objects’ ratings decrease over time? IE something like:
Model.order('popularity-integerize(created_at) ASC')
So: how might I do this, and is it efficient?
When calculating your popularity, you could just keep the creation time into consideration 😉