i have in controller:
@players = player.all.order(:last_name).group_by{|player| player.last_name[0]}
and in view have:
- @players.each |letter, players| %h2= letter - players.each |player|
this results in players being grouped alphabetically, not ordered alphabetically within groups, e.g:
- almunia
- adams
- angha
- etc
in other words, adams should come before almunia of course.
what doing wrong?
a little surprising, i'm not sure group_by
guarantees order of elements once grouped. fix adjust players.each
loop players.sort_by(&:last_name).each
Comments
Post a Comment