一覧を表示する順番を指定する
indexアクションは初期段階では
Tweet.all
などで記述していると思うが、順番を並べ替えたい時の記述方法
@tweets = Tweet.all.order(created_at: :desc) #=>新しい順の投稿一覧 #created_atは作成日時 descは降順 @tweets = Tweet.all.order(created_at: :asc)#=> 古い順の投稿一覧 #created_atは作成日時 ascは昇順
indexアクションは初期段階では
Tweet.all
などで記述していると思うが、順番を並べ替えたい時の記述方法
@tweets = Tweet.all.order(created_at: :desc) #=>新しい順の投稿一覧 #created_atは作成日時 descは降順 @tweets = Tweet.all.order(created_at: :asc)#=> 古い順の投稿一覧 #created_atは作成日時 ascは昇順