Make it easier to re-apply default sort orders
By moving the default sort order into a separate scope (and calling this from the default scope) we can more easily re-apply a default order without having to specify the exact column/ordering all over the place.
This commit is contained in:
parent
028bd227fb
commit
656d9ff69b
1 changed files with 2 additions and 1 deletions
|
@ -8,8 +8,9 @@ module Sortable
|
||||||
included do
|
included do
|
||||||
# By default all models should be ordered
|
# By default all models should be ordered
|
||||||
# by created_at field starting from newest
|
# by created_at field starting from newest
|
||||||
default_scope { order(id: :desc) }
|
default_scope { order_id_desc }
|
||||||
|
|
||||||
|
scope :order_id_desc, -> { reorder(id: :desc) }
|
||||||
scope :order_created_desc, -> { reorder(created_at: :desc) }
|
scope :order_created_desc, -> { reorder(created_at: :desc) }
|
||||||
scope :order_created_asc, -> { reorder(created_at: :asc) }
|
scope :order_created_asc, -> { reorder(created_at: :asc) }
|
||||||
scope :order_updated_desc, -> { reorder(updated_at: :desc) }
|
scope :order_updated_desc, -> { reorder(updated_at: :desc) }
|
||||||
|
|
Loading…
Reference in a new issue