Module: MailerProcess

Defined in:
lib/mailer_process.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



2
3
4
5
6
7
# File 'lib/mailer_process.rb', line 2

def self.included(base)
  base.class_eval { 
    alias_method_chain :process, :mailer 
    attr_accessor :last_mail
  }
end

Instance Method Details

#process_with_mailer(request, response) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/mailer_process.rb', line 9

def process_with_mailer(request, response)
  # If configured to do so, receive and process the mailer POST
  if Radiant::Config['mailer.post_to_page?'] && request.post? && request.parameters[:mailer]
    config, part_page = mailer_config_and_page

    mail = Mail.new(part_page, config, request.parameters[:mailer])
    self.last_mail = part_page.last_mail = mail
    process_mail(mail, config)

    if mail.send
      response.redirect(config[:redirect_to], "302 Found") and return if config[:redirect_to]
      # Clear out the data and errors so the form isn't populated, but keep the success status around.
      self.last_mail.data.delete_if { true }
      self.last_mail.errors.delete_if { true }
    end
  end
  process_without_mailer(request, response)
end