Skip to content

Commit

Permalink
Fix: handle multiple attachements file
Browse files Browse the repository at this point in the history
  • Loading branch information
BoutValentin authored and carlosantoniodasilva committed Nov 4, 2022
1 parent f162bcb commit 761bee3
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions lib/mail_form/notifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,27 @@ def contact(resource)

resource.class.mail_attachments.each do |attribute|
value = resource.send(attribute)
next unless value.respond_to?(:read)
attachments[value.original_filename] = value.read
handle_multiple_attachments value
add_attachment value
end

headers = resource.headers
headers[:from] ||= resource.email
headers[:subject] ||= resource.class.model_name.human
mail(headers)
end

private
def add_attachment(attch)
return unless attch.respond_to?(:read)
attachments[attch.original_filename] = attch.read
end

def handle_multiple_attachments(attchs)
return unless attchs.respond_to?('each')
attchs.each do |attch|
add_attachment attch
end
end
end
end
end

0 comments on commit 761bee3

Please sign in to comment.