Skip to content

Commit 5fa6c05

Browse files
committed
update set_has_attachment
1 parent 5d93649 commit 5fa6c05

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

app/models/report.rb

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ class Report < ApplicationRecord
1111
FORM_FILE_CONTENT_TYPES = %w[application/pdf application/msword application/vnd.openxmlformats-officedocument.wordprocessingml.document application/vnd.ms-excel application/vnd.openxmlformats-officedocument.spreadsheetml.sheet]
1212

1313
if ENV["ACTIVE_STORAGE"].present?
14-
# TODO handle set_has_attachment
14+
# TODO verify set_has_attachament works as expected once this feature is enabled in the UI
1515
has_one_attached :form_file
1616
validates :form_file, content_type: FORM_FILE_CONTENT_TYPES
17+
18+
before_save :set_has_attachament
1719
else
1820
has_attached_file :form_file
1921
before_save :set_has_attachament
@@ -136,10 +138,14 @@ def display_date
136138
private
137139

138140
def set_has_attachament
139-
self.has_attachment = false
141+
if ENV["ACTIVE_STORAGE"].present?
142+
self.has_attachment = image.attached? || form_file.attached? || media_files.any? { |media_file| media_file.file.attached? }
143+
else
144+
self.has_attachment = false
140145

141-
unless self.image.blank? and self.media_files.empty? and self.form_file.blank?
142-
self.has_attachment = true
146+
unless image.blank? && media_files.empty? && form_file.blank?
147+
self.has_attachment = true
148+
end
143149
end
144150
end
145151

0 commit comments

Comments
 (0)