From a very small number, I got your question, I think you want something like the following
answers = QuizuserAnswer.all(:include =>:user, :select => 'user_id, SUM(answer) AS points', :group =>'user_id', :order=>'points DESC') user_id = 348 answers.map(&:user_id).index(user_id)
ie It will return the position of the response specified by the user among the list of answers
Salil source share