RailsCasts Pro episodes are now free!

Learn more or hide this

Pieter Gunst's Profile

GitHub User: digitallawyer

Site: www.lawgives.com

Comments by Pieter Gunst

Avatar

I'm having trouble moving the code that generates the pdf from the controller to a separate ruby file.

I have the following code in the relevant part of my controller:

def show
@corporation = Corporation.find(params[:id])

respond_to do |format|
  format.html # show.html.erb
  format.json { render json: @corporation }
  format.pdf do
    pdf = CertificatePdf.new
    send_data pdf.render, type: "application/pdf", disposition: "inline"

I created a separate certificate_pdf.rb file in the folder app/pdfs which contains the following code:

class CertificatePdf < Prawn::Document
    def intitialize
        super
        text "Help"
    end
end

However, when I open the generated pdf the document is blank. Any thougths?