I have a Rails app that allows voting on some models. In one of my models I want to change the default_scope
so that objects that has the most votes is displayed first. I have tried the following in my model file:
def self.default_scope
order('votes_for.size DESC')
end
This gives me the following error:
SQLite3::SQLException: no such column: votes_for.size: SELECT "solutions".* FROM "solutions" WHERE "solutions"."competition_id" = ? ORDER BY votes_for.size DESC
I wonder if there is a way the change the default default sort order, what I'm doing is obviously not working.
Solutions for making it work in the controller level (not default order) would also be nice, if that's possible.