rails order
find の中で order を指定すると、ソートの仕方が設定できる。
デフォルト
@students = Student.all
昇順でソート
@students = Student.find(:all, :order => "student_name ASC")
降順でソート
@students = Student.find(:all, :order => "student_name DESC")
複数条件でソートする時は、カンマで条件を区切って追加。
@students = Student.find(:all, :order => "student_name DESC, created_at ASC")
履歴
- 第 2 版tamasally 2012-05-17 11:01:25
- 第 1 版tamasally 2012-05-17 11:01:18