Class: Maily::EmailsController

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

Instance Method Summary collapse

Instance Method Details

#attachmentObject



29
30
31
32
33
# File 'app/controllers/maily/emails_controller.rb', line 29

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

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

#deliverObject



45
46
47
48
49
50
51
# File 'app/controllers/maily/emails_controller.rb', line 45

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



35
36
37
# File 'app/controllers/maily/emails_controller.rb', line 35

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
# File 'app/controllers/maily/emails_controller.rb', line 19

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

  render html: content.raw_source, 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



39
40
41
42
43
# File 'app/controllers/maily/emails_controller.rb', line 39

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