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



20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/letter_opener_web/letters_controller.rb', line 20

def attachment
  @letter = Letter.find(params[:id])
  filename = "#{params[:file]}.#{params[:format]}"

  if file = @letter.attachments[filename]
    send_file(file, :filename => filename, :disposition => 'inline')
  else
    render :plain => 'Attachment not found!', :status => 404
  end
end

#clearObject



31
32
33
34
# File 'app/controllers/letter_opener_web/letters_controller.rb', line 31

def clear
  Letter.destroy_all
  redirect_to LetterOpenerWeb.railtie_routes_url_helpers.letters_path
end

#destroyObject



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

def destroy
  @letter = Letter.find(params[:id])
  @letter.delete
  redirect_to LetterOpenerWeb.railtie_routes_url_helpers.letters_path
end

#indexObject



8
9
10
# File 'app/controllers/letter_opener_web/letters_controller.rb', line 8

def index
  @letters = Letter.search
end

#showObject



12
13
14
15
16
17
18
# File 'app/controllers/letter_opener_web/letters_controller.rb', line 12

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

  render :html => text.html_safe
end