When changing the sort of posted data or articles, is the desc in descending order? descending order? I googled it every time, so I summarized it.
board.rb
class Board < ApplicationRecord
scope :desc, -> { order(created_at: :desc) } #Descending order of creation
scope :asc, -> { order(id: :asc) } #Ascending order of id Since it is written in asc (ascending order) by default, it is rare to write it explicitly.
end
Recommended Posts