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



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

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

  return render plain: 'Attachment not found!', status: 404 unless file.present?

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

#clearObject



33
34
35
36
# File 'app/controllers/letter_opener_web/letters_controller.rb', line 33

def clear
  Letter.destroy_all
  redirect_to routes.letters_path
end

#destroyObject



38
39
40
41
# File 'app/controllers/letter_opener_web/letters_controller.rb', line 38

def destroy
  @letter.delete
  redirect_to routes.letters_path
end

#indexObject



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

def index
  @letters = Letter.search
end

#showObject



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

def show
  text = @letter.send("#{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