3

次のlink_toパスがあります。

http:// localhost:3000 / letters / showpdf / 3

レターコントローラーに次のカスタムアクションがあります。

 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

現在、ブラウザに何も返されません。

編集:これは私がルビーのログに見るものです:

Processing LettersController#showpdf (for 127.0.0.1 at 2011-02-18 15:10:31) [GET]
  Parameters: {"action"=>"showpdf", "id"=>"3", "controller"=>"letters"}
  Letter Load (1.5ms)   SELECT * FROM "letters" WHERE ("letters"."id" = 3) 
Sending data pdf.pdf
Completed in 1917ms (View: 6, DB: 2) | 200 OK [http://localhost/letters/showpdf/3]
4

1 に答える 1

9

これは、PDFkit のコントローラーで使用するものです。

send_data @pdf, :filename => "whatever.pdf",
                :type => "application/pdf",
                :disposition  => "inline" # either "inline" or "attachment"

お役に立てれば

于 2011-02-19T00:56:53.790 に答える