Files
grecia/app/models/widget/card.rb
taitus 108de86da5 Add link_url validation for cards when are header cards
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.
2021-06-28 15:59:04 +02:00

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