Class: Maily::EmailsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/maily/emails_controller.rb

Instance Method Summary collapse

Instance Method Details

#attachmentObject



32
33
34
35
36
# File 'app/controllers/maily/emails_controller.rb', line 32

def attachment
  attachment = @email.attachments.find { |elem| elem.filename == params[:attachment] }

  send_data attachment.body, filename: attachment.filename, type: attachment.content_type
end

#deliverObject



48
49
50
51
52
53
54
# File 'app/controllers/maily/emails_controller.rb', line 48

def deliver
  @email.to = params[:to]

  @email.deliver

  redirect_to maily_email_path(mailer: params[:mailer], email: params[:email]), notice: "Email sent to <b>#{params[:to]}</b>!"
end

#editObject



38
39
40
# File 'app/controllers/maily/emails_controller.rb', line 38

def edit
  @template = @maily_email.template(params[:part])
end

#indexObject



8
9
# File 'app/controllers/maily/emails_controller.rb', line 8

def index
end

#rawObject



19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/maily/emails_controller.rb', line 19

def raw
  content = if @email.multipart?
    params[:part] == 'text' ? @email.text_part.body : @email.html_part.body
  else
    @email.body
  end

  content = content.raw_source
  content = view_context.simple_format(content) if @email.sub_type == 'plain' || params[:part] == 'text'

  render html: content.html_safe, layout: false
end

#showObject



11
12
13
14
15
16
17
# File 'app/controllers/maily/emails_controller.rb', line 11

def show
  valid, message = @maily_email.validate_arguments

  unless valid
    redirect_to(root_path, alert: message)
  end
end

#updateObject



42
43
44
45
46
# File 'app/controllers/maily/emails_controller.rb', line 42

def update
  @maily_email.update_template(params[:body], params[:part])

  redirect_to maily_email_path(mailer: params[:mailer], email: params[:email], part: params[:part]), notice: 'Template updated!'
end