How do I sort in ruby/rails on two fields?

后端 未结 5 514
星月不相逢
星月不相逢 2020-12-14 05:59

For example, I would like to sort by game_date, and then if the date is the same, sort it by team? What would be the best way to do this?

@teams = @user.tea         


        
5条回答
  •  一个人的身影
    2020-12-14 06:42

    Assuming that you have a model which have these two fields

    Model.all(:order => 'attribute1, attribute2')

    Incase the fields are in multiple tables, you can use joins.

提交回复
热议问题