Class: LetterOpenerWeb::LettersController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- LetterOpenerWeb::LettersController
- Defined in:
- app/controllers/letter_opener_web/letters_controller.rb
Instance Method Summary collapse
Instance Method Details
#attachment ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'app/controllers/letter_opener_web/letters_controller.rb', line 25 def filename = "#{letter_params[:file]}.#{letter_params[:format]}" file = @letter.[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 |
#clear ⇒ Object
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 |
#destroy ⇒ Object
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 |
#index ⇒ Object
13 14 15 |
# File 'app/controllers/letter_opener_web/letters_controller.rb', line 13 def index @letters = letter_model.search end |
#show ⇒ Object
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 |