Allow sorting widget_cards on homepage
Note that we keep :created_at order as complement to new :order field. We do this so that current installations will not notice any change in the sorting of their cards when upgrading, as the default "order" field will always be 1, so it will continue to sort by the "created_at".
This commit is contained in:
@@ -12,12 +12,14 @@ class Widget::Card < ApplicationRecord
|
||||
validates :link_url, presence: true, if: -> { !header? || link_text.present? }
|
||||
validates :order, numericality: { greater_than_or_equal_to: 1 }
|
||||
|
||||
scope :sort_by_order, -> { order(:order, :created_at) }
|
||||
|
||||
def self.header
|
||||
where(header: true)
|
||||
end
|
||||
|
||||
def self.body
|
||||
where(header: false, cardable_id: nil).order(:created_at)
|
||||
where(header: false, cardable_id: nil).sort_by_order
|
||||
end
|
||||
|
||||
def header_or_sdg_header?
|
||||
|
||||
Reference in New Issue
Block a user