announcement.rb 363 B

12345678910111213
  1. class Announcement < ApplicationRecord
  2. TYPES = %w{ new fix update }
  3. after_initialize :set_defaults
  4. validates :announcement_type, :description, :name, :published_at, presence: true
  5. validates :announcement_type, inclusion: { in: TYPES }
  6. def set_defaults
  7. self.published_at ||= Time.zone.now
  8. self.announcement_type ||= TYPES.first
  9. end
  10. end