Add link_url presence validation only when link_text is provided only for header cards. In this case it makes sense to allow creating a "header card" without link_url, since we can show the header without link text and without link url and it still does its function.
22 lines
548 B
Ruby
22 lines
548 B
Ruby
class Widget::Card < ApplicationRecord
|
|
include Imageable
|
|
belongs_to :cardable, polymorphic: true
|
|
|
|
translates :label, touch: true
|
|
translates :title, touch: true
|
|
translates :description, touch: true
|
|
translates :link_text, touch: true
|
|
include Globalizable
|
|
|
|
validates_translation :title, presence: true
|
|
validates :link_url, presence: true, if: -> { !header? || link_text.present? }
|
|
|
|
def self.header
|
|
where(header: true)
|
|
end
|
|
|
|
def self.body
|
|
where(header: false, cardable_id: nil).order(:created_at)
|
|
end
|
|
end
|