Class: MailForm::Notifier

Inherits:
ActionMailer::Base
  • Object
show all
Defined in:
lib/mail_form/notifier.rb

Instance Method Summary collapse

Instance Method Details

#contact(resource) ⇒ Object


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/mail_form/notifier.rb', line 6

def contact(resource)
  if resource.request.nil? && resource.class.mail_appendable.any?
    raise ScriptError, "You set :append values but forgot to give me the request object"
  end

  @resource = @form = resource

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

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