我正在使用 PDFKit 和它的 Middlware 将 HTML 呈现为 PDF,但是当我尝试转到 localhost:3000/booklets/1.pdf 时它一直出现 TypeError
can't convert Hash into String
它说错误在 BookletsController#show 中。这是我的booklets_controller.rb的摘录
def show
@booklet = Booklet.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.pdf {
html = render_to_string(:action => "show.html.erb", :formats => [:html])
kit = PDFKit.new(html)
send_data(kit.to_pdf, :filename => "booklet.pdf", :type => 'application/pdf')
return
}
end
end
环境.rb
# Initialize the rails application
Ziin::Application.initialize!
Mime::Type.register "application/pdf", :pdf
摘自application.rb
require 'pdfkit'
config.middleware.use "PDFKit::Middleware"
PDFKit.configure do |config|
config.wkhtmltopdf = { :exe_path => '/usr/local/bin/wkhtmltopdf' }
end