From 2fde02c7ec78c76b1773e826c4dc1f922337b99b Mon Sep 17 00:00:00 2001 From: Chris Oliver Date: Sun, 13 Jun 2021 15:55:50 -0500 Subject: [PATCH] Add default value for Announcement published_at --- app/models/announcement.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/models/announcement.rb b/app/models/announcement.rb index 6dd28ed8..c58fab18 100644 --- a/app/models/announcement.rb +++ b/app/models/announcement.rb @@ -16,4 +16,10 @@ class Announcement < ApplicationRecord has_rich_text :description validates :kind, :title, :description, :published_at, presence: true + + after_initialize :set_defaults + + def set_defaults + self.published_at ||= Time.current + end end