我采用了Railscast第153集修订版的方法。
我控制器未初始化的常量Prawn :: FLOAT_PRECISION在使用对象时显示的错误
class AdminsController < ApplicationController
def index
@examples = Example.all
respond_to do |format|
format.html
format.csv { send_data @examples.to_csv }
format.xls { send_data @examples.to_csv }
format.pdf do
pdf = DownloadPdf.new(@examples)
send_data pdf.render, filename: 'generate_table.pdf',
type: 'application/pdf', disposition: "inline"
end
end
end
end
和我download_pdf.rb文件
class DownloadPdf < Prawn::Document#make_table
require 'prawn/table'
def initialize(example)
super()
@examples = example
line_items
end
def line_items
image "#{Rails.root}/app/assets/images/logo.png"
table [[1,2],[3,4]]
end
end
我使用宝石
gem 'prawn', :git => "https://github.com/prawnpdf/prawn.git", :ref => '8028ca0cd2' gem 'prawn-table', '~> 0.1.0'
Thanx提前帮助。
非常感谢,它的工作 – 2015-02-23 08:55:56
太好了!不要忘了标记答案已被接受/ upvote,如果它帮助你。 – dgilperez 2015-02-23 08:57:34