LoginSignup
96

More than 5 years have passed since last update.

rails 昇順、降順の並び替え

Posted at

データを昇順、降順に並び替えたいとき、どうやるんだっけ?とできそうでできない、かゆい感じだったので、まとめてみた。

@user = User.all.order(id: "DESC") ## idの降順
@user = User.all.order(bith_day: "ASC") ## 生年月日の昇順(デフォルトがASCになっているので通常この書き方はない)

@user = User.all.order(:id) ## 昇順or降順を指定しない場合(デフォルトは)昇順

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
What you can do with signing up
96