File tree Expand file tree Collapse file tree 1 file changed +10
-4
lines changed Expand file tree Collapse file tree 1 file changed +10
-4
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments