Class: LetterOpenerWeb::LettersController

Inherits:
ApplicationController show all
Defined in:
app/controllers/letter_opener_web/letters_controller.rb

Instance Method Summary collapse

Instance Method Details

#attachmentObject



25
26
27
28
29
30
31
32
33
# File 'app/controllers/letter_opener_web/letters_controller.rb', line 25

def attachment
  filename = "#{letter_params[:file]}.#{letter_params[:format]}"
  file     = @letter.attachments[filename]

  return render plain: 'Attachment not found!', status: 404 unless file.present?
  return redirect_to(file, allow_other_host: true) if LetterOpenerWeb.config.letters_storage == :s3

  send_file(file, filename:, disposition: 'inline')
end

#clearObject



35
36
37
38
# File 'app/controllers/letter_opener_web/letters_controller.rb', line 35

def clear
  letter_model.destroy_all
  redirect_to routes.letters_path
end

#destroyObject



40
41
42
43
44
45
46
# File 'app/controllers/letter_opener_web/letters_controller.rb', line 40

def destroy
  @letter.delete
  respond_to do |format|
    format.html { redirect_to routes.letters_path }
    format.js { render js: "window.location='#{routes.letters_path}'" }
  end
end

#indexObject



13
14
15
# File 'app/controllers/letter_opener_web/letters_controller.rb', line 13

def index
  @letters = letter_model.search
end

#showObject



17
18
19
20
21
22
23
# File 'app/controllers/letter_opener_web/letters_controller.rb', line 17

def show
  text = @letter.send("#{letter_params[:style]}_text")
                .gsub('"plain.html"', "\"#{routes.letter_path(id: @letter.id, style: 'plain')}\"")
                .gsub('"rich.html"', "\"#{routes.letter_path(id: @letter.id, style: 'rich')}\"")

  render html: text.html_safe
end