retrospring/app/models/announcement.rb

19 lines
438 B
Ruby
Raw Normal View History

2020-04-19 21:12:22 +02:00
class Announcement < ApplicationRecord
2020-04-19 21:34:48 +02:00
belongs_to :user
2020-04-19 22:11:22 +02:00
validates :content, presence: true
validates :starts_at, presence: true
validates :link_href, presence: true, if: -> { link_text.present? }
validate :starts_at, :validate_date_range
def link_present?
link_text.present?
end
def validate_date_range
if starts_at > ends_at
errors.add(:starts_at, "Start date must be before end date")
end
end
2020-04-19 21:12:22 +02:00
end