I have 2 tables (relationships many-to-many with sqlite3) : -User -Credit(with user_id & score)
And I try to compute the rank of the user. To compute the rank of this user I need to find the SUM of all the credits of this user. But I don't know how do this :(
I have tried something like this but it don't work :
User.all.join(:credits).order(sum(:score)).index(@user)
I get this error :
TypeError in UsersController#index
can't convert Symbol into String
Thank !
:credits
and:score
?sum' for #<String:0xb5ce7c54> And when I delete the sum : ( User.all.join("credits").order("score").index(@user) ) undefined method
order' for #<String:0xb5695a7c>.all
command, you fetch the result ... It returns an array and not a query object so you cannot use any operations like order, join, etc on them ... Put the .all to the end