Sha256: 72cee77ff5199bf0b68526012364e19e75b5b9b928fab837378568fbea22193c
Contents?: true
Size: 1.55 KB
Versions: 1
Compression:
Stored size: 1.55 KB
Contents
require_dependency "letter_opener_web/application_controller" module LetterOpenerWeb class LettersController < ApplicationController before_action :check_style, :only => [:show] before_action :load_letter, :only => [:show, :attachment, :destroy] def index @letters = Letter.search end 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 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 def clear Letter.destroy_all redirect_to LetterOpenerWeb.railtie_routes_url_helpers.letters_path end def destroy @letter = Letter.find(params[:id]) @letter.delete redirect_to LetterOpenerWeb.railtie_routes_url_helpers.letters_path end private def check_style params[:style] = 'rich' unless ['plain', 'rich'].include? params[:style] end def load_letter if params[:id] @letter = Letter.find(params[:id]) head :not_found unless @letter.exists? end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
letter_opener_web-1.3.1 | app/controllers/letter_opener_web/letters_controller.rb |