File tree Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Original file line number Diff line number Diff line change @@ -8,13 +8,14 @@ class Report < ApplicationRecord
88  has_one  :image 
99  validate  :image_valid? 
1010
11-   # before_save :set_has_attachament # TODO handle set_has_attachment 
1211  FORM_FILE_CONTENT_TYPES  =  %w[ application/pdf  application/msword 
1312    application/vnd.openxmlformats-officedocument.wordprocessingml.document  application/vnd.ms-excel 
1413    application/vnd.openxmlformats-officedocument.spreadsheetml.sheet ] 
1514  has_one_attached  :form_file 
1615  validates  :form_file ,  content_type : FORM_FILE_CONTENT_TYPES 
1716
17+   before_save  :set_has_attachament  # TODO verify set_has_attachament works as expected once this feature is enabled in the UI 
18+ 
1819  has_many  :images 
1920  has_many  :form_fields ,  through : :form 
2021  has_many  :report_form_field_answers ,  dependent : :destroy 
@@ -130,10 +131,14 @@ def display_date
130131  private 
131132
132133  def  set_has_attachament 
133-     self . has_attachment  =  false 
134+     if  ENV [ "ACTIVE_STORAGE" ] . present? 
135+       self . has_attachment  =  image . attached?  || form_file . attached?  || media_files . any?  {  |media_file | media_file . file . attached?  } 
136+     else 
137+       self . has_attachment  =  false 
134138
135-     unless  self . image . blank?  and  self . media_files . empty?  and  self . form_file . blank? 
136-       self . has_attachment  =  true 
139+       unless  image . blank?  && media_files . empty?  && form_file . blank? 
140+         self . has_attachment  =  true 
141+       end 
137142    end 
138143  end 
139144
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments