我一直在用prawn创建pdf文档。我正在使用虾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
这是我在控制器中的show动作的代码
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'
可能出错?
答案 0 :(得分:2)
升级到Prawn版本0.12.0
,它应该可以正常工作。