class AddEmailAuditToNotifications < ActiveRecord::Migration[7.0]
def change
add_column :notifications, :sent_at, :datetime
add_column :notifications, :recipient_email, :string
add_column :notifications, :email_subject, :string
add_column :notifications, :email_body, :text
end
end
def send_notice
mail = Admins::NotificationMailer.email(self)
mail.deliver_now
update_columns(
sent_at: Time.current,
recipient_email: Array(mail.to).join(', '),
email_subject: mail.subject,
email_body: mail.body.decoded
)
rescue StandardError => e
Rails.logger.error("Failed to send notification ##{id}: #{e.message}")
end
def resend
mail = Admins::NotificationMailer.email(self)
mail.deliver_now
update_columns(
sent_at: Time.current,
recipient_email: Array(mail.to).join(', '),
email_subject: mail.subject,
email_body: mail.body.decoded
)
rescue StandardError => e
Rails.logger.error("Failed to resend notification ##{id}: #{e.message}")
end
class AddEmailAuditToNotifications < ActiveRecord::Migration[7.0]
def change
add_column :notifications, :sent_at, :datetime
add_column :notifications, :recipient_email, :string
add_column :notifications, :email_subject, :string
add_column :notifications, :email_body, :text
end
end
def send_notice
mail = Admins::NotificationMailer.email(self)
mail.deliver_now
update_columns(
sent_at: Time.current,
recipient_email: Array(mail.to).join(', '),
email_subject: mail.subject,
email_body: mail.body.decoded
)
rescue StandardError => e
Rails.logger.error("Failed to send notification ##{id}: #{e.message}")
end
def resend
mail = Admins::NotificationMailer.email(self)
mail.deliver_now
update_columns(
sent_at: Time.current,
recipient_email: Array(mail.to).join(', '),
email_subject: mail.subject,
email_body: mail.body.decoded
)
rescue StandardError => e
Rails.logger.error("Failed to resend notification ##{id}: #{e.message}")
end