i’m having a users model that has a method score, which actually gets a sum of the score of solved challenges :
def score
self.challenge_level_solutions.inject(0) do |sum, x|
sum + x.challenge_level.points
end
end
Now, i have a Kaminari related controller action like :
def index
@users = User.page(params[:page])
end
My problem is how i would go about displaying the user score in DESC order, that is show the users with a better score about others with a lower score. My view is :
<% @users.each_with_index do |user, index| %>
<%= user.username %> - <%= user.score %>
<br>
<% end %>
and shows :
1. user1 - 0
2. user2 - 0
3. user3 - 2
Any ideas so that it shows properly, with user3 on the first place ?
1 Answer