I would like to render a partial that sorts by score, then by name (if multiple players have the same score).
Right now I am using this:
<%= render @players.sort_by { |p| [p.scored_vote(current_week), p.last_name] } %>
This works, but it is sorting the scores in ascending order, and I would like to sort them in descending order. How can I flip the sort order for the score, but not for name, which I would still like to sort in ascending order?
Thanks!
You question has nothing to do with rendering partials. what you are interested in is the behaviour of sort_by method . In btw, this should solve your problem:
<%= render @players.sort_by { |p| [-p.scored_vote(current_week), p.last_name] } %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With