title: Sort a list with multiple conditions Ruby on Rails
body: <p>I want to be able to rank 12 teams in a list according to 4 different criteria. </p>
  
  <p>I will have a db table called Teams and each team will have various columns like matches_won, matches_lost, etc...</p>
  
  <p>I want to display them in order based on matches_won. This is easy. However, if two teams are tied in matches_won then I must check whether they have played each other and who won. If they have the same matches_won AND have not played each other, their records are compared on two other criteria and ranked by that. I think if I can figure out how to do one additional condition to the sort that I will be able to figure out how to do the others. So for brevity's sake, I won't detail them here.</p>
  
  <p>I don't know how to do this multi-level sorting in Rails.</p>
  
  <p>I have thought maybe adding a 'rank' column in the db table and before_save function that ranks them going into the db and then simply listing them in the view based on that rank. But that leaves me with the same problem (not knowing how to do conditional sorting) it just  does it before the save rather than when I read it out of the db.</p>
  
  <p>Any help would be appreciated!</p>