We didn't add any validation rules to the card model. At the very least, the title should be mandatory. The fact that the label field is marked as optional in the form but the other fields are not probably means description and link should be mandatory as well. However, since there might be institutions using cards with descriptions but no link or cards with links but no description, so we're keeping these fields optional for compatibility reasons. We might change our minds in the future, though.
27 lines
667 B
Ruby
27 lines
667 B
Ruby
class Widget::Card < ApplicationRecord
|
|
include Imageable
|
|
belongs_to :page,
|
|
class_name: "SiteCustomization::Page",
|
|
foreign_key: "site_customization_page_id",
|
|
inverse_of: :cards
|
|
|
|
# table_name must be set before calls to 'translates'
|
|
self.table_name = "widget_cards"
|
|
|
|
translates :label, touch: true
|
|
translates :title, touch: true
|
|
translates :description, touch: true
|
|
translates :link_text, touch: true
|
|
include Globalizable
|
|
|
|
validates_translation :title, presence: true
|
|
|
|
def self.header
|
|
where(header: true)
|
|
end
|
|
|
|
def self.body
|
|
where(header: false, site_customization_page_id: nil).order(:created_at)
|
|
end
|
|
end
|