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
24
25
26
# 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)
    if value.is_a?(Array)
      value.each { |attachment_file| add_attachment(attachment_file) }
    else
      add_attachment(value)
    end
  end

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