Sha256: f5da8300025feebf0208607fdbe9098cd7099031bddf747cd1fa1d4f576beadf

Contents?: true

Size: 1.39 KB

Versions: 1

Compression:

Stored size: 1.39 KB

Contents

module GBDev #:nodoc: all

  module Utils
    
    module PrivateMethods
  
      def build_random_string # :nodoc:
        letters_array = [('a'..'z'),('A'..'Z')].collect{|i| i.to_a}.flatten
        (1..10).collect{ letters_array[ rand(letters_array.length) ] }.join 
      end
      
      def build_random_file_name # :nodoc:
        build_random_string << '.pdf'
      end              
  
    end
    
    
    # Include these controller methods to prompt the user to download the PDF.
    #
    # * include GBDev::Utils::ControllerMethods
    module ControllerMethods
      
      # Used to display the PDF without saving it to disk.
      # 
      # * buffer - A Page buffer or Book buffer.
      # * filename - The filename to apply to the buffer when prompted to download.
      def display_pdf(buffer, filename)
        send_data(buffer, {:type        => 'application/pdf',
                           :disposition => 'attachment',
                           :filename    => filename} )
      end
      

      # From here: http://railspdfplugin.rubyforge.org/wiki/wiki.pl
      # Suggested code so errors will always show in browser
      def rescue_action_in_public(exception) # :nodoc:
        headers.delete("Content-Disposition")
        super
      end

      def rescue_action_locally(exception) # :nodoc:
        headers.delete("Content-Disposition")
        super
      end
      
    end
    
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gbdev-pdf_filler-0.3.3 lib/pdf_filler/util_methods.rb