【发布时间】:2013-06-10 08:03:22
【问题描述】:
我一直在用虾制作 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
这是我在控制器中显示操作的代码
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 Railscast,其代码似乎可以工作。也许这是一个版本问题......?你可以尝试将 Prawn 升级到
1.0.0.rc2,或者至少升级到0.12.0,看看是否有帮助? -
是的,只需要升级到
0.12.0
标签: ruby-on-rails-3 prawn