ruby on rails - How do I render to the browser a PDF using PDFKit? -
i have following link_to path:
http://localhost:3000/letters/showpdf/3
i have following custom action in letters controller:
def showpdf @letter = letter.find(params[:id]) @redcloth_letter = " <style type='text/css'> </style>" @redcloth_letter = @redcloth_letter << redcloth.new(@letter.body).to_html pdf = pdfkit.new(@redcloth_letter) pdf.stylesheets << "#{rails_root}/public/stylesheets/compiled/pdf.css" send_data(pdf.to_pdf, :filename => "pdf.pdf") end
i nothing returning browser.
edit: see in ruby logs:
processing letterscontroller#showpdf (for 127.0.0.1 @ 2011-02-18 15:10:31) [get] parameters: {"action"=>"showpdf", "id"=>"3", "controller"=>"letters"} letter load (1.5ms) select * "letters" ("letters"."id" = 3) sending data pdf.pdf completed in 1917ms (view: 6, db: 2) | 200 ok [http://localhost/letters/showpdf/3]
this use in controller pdfkit.
send_data @pdf, :filename => "whatever.pdf", :type => "application/pdf", :disposition => "inline" # either "inline" or "attachment"
hope helps
Comments
Post a Comment