テックキャンプのカリキュラムの復習です!
いいねお願いします!
ruby
目的
- orderメソッドの理解
投稿最新順表示
レコードの取得順変更
orderメソッド
ActiveRecordメソッド
テーブルから取得してきた複数のレコード情報を持つインスタンスの、並び順を変更するメソッド
インスタンス = モデル名.order("並び替えの基準となるカラム名 並び順")
ASC(昇順) DESC(降順)
app/controllers/tweets_controller.rb
def index
@tweets = Tweet.includes(:user).order("created_at DESC")