0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

rails app 取得したデータを並び替えるには orderメソッド

Posted at

結論

orderメソッドを使う。
取得したデータを並び替えるメソッド。

モデル名.order(並び替えたいカラム名:)

具体例

モデル名:userの時

app/controller/モデル名_controller.rb

class UsersController < ApplicationController

def
@users = User.order(:id)
end
# @usersに格納している、右の内容を
# idの順番で並べる。
end

一旦、以上です。

0
0
0

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
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?