我正在尝试通过 Prawn 将 pdf 生成添加到我的 Rails 3 应用程序中。我正在关注 Railscast,一切都很顺利,直到我尝试将一个实例变量从我的控制器传递给我创建的单独类。
控制器动作如下所示:
def show #shows some material
@material = Material.find(params[:id])
respond_to do |format|
format.html
format.pdf do
pdf = MaterialPdf.new(@material)
send_data pdf.render, filename: "material_#{@material.id}.pdf",
type: "application/pdf",
disposition: "inline"
end
end
结尾
material_pdf.rb 文件如下所示:
class MaterialPdf < Prawn::Document
def initialize(material)
super
@material = material
text "Placeholder text"
end
end
我从日志中得到的错误信息很奇怪:
Material Load (0.1ms) SELECT "materials".* FROM "materials" WHERE "materials"."id" = ? ORDER BY materials.created_at DESC LIMIT 1 [["id", "27"]]
DEPRECATION WARNING: You're trying to create an attribute `info'. Writing arbitrary attributes on a model is deprecated. Please just use `attr_writer` etc. (called from initialize at .../app/pdfs/material_pdf.rb:3)
这很奇怪,因为查询看起来很好,而且我没有尝试创建属性“信息”。我不明白。帮助。