我一直在用 Prawn 创建 pdf 文档。我用的是 Prawn 0.8.4。我像这样在 app 目录的 pdf 文件夹中创建了一个类。
class SchoolPdf < Prawn::Document
def initialize(school)
super(top_margin: 70)
@school = school
school_name
line_items
end
def school_name
text "School: #{@school.school_name}", size: 30, style: :bold
end
def line_items
move_down 20
table [[1,2],[3,4]]
end
end
这是我在 Controller 中显示 Action 的代码
def show
@school = School.find(params[:id])
respond_to do |format|
format.html
format.pdf do
pdf = SchoolPdf.new(@school)
send_data pdf.render,filename: "#{@school.school_name}_report.pdf",
type: "application/pdf",
disposition: "inline"
end
我收到错误 undefined method 'table'
可能出了什么问题?
最佳答案
升级到 Prawn 版本 0.12.0
,它应该可以工作。
关于ruby-on-rails-3 - Prawn 表法不行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17019363/