我有一个继承自OrderPdf
的{{1}}类,这是该类的内容:
Prawn::Document
我这样称呼它:class OrderPdf < Prawn::Document
include ActionView::Helpers::NumberHelper
include ActionView::Helpers::TagHelper
def initialize(order)
super(top_margin: 50, size: 12)
@order = order
logo
# Other methods that generate pdf's content
footer
end
def logo
# Some stuff here
end
def footer
#Some stuff here
end
end
。 Pdf文件已生成,但是我需要的是-使用以下名称将其保存到我的项目中:OrderPdf.new(@order)
我知道,我可以这样做:"#{Rails.root}/public/uploads/orders/order-#{order.order_number}.pdf"
,但是我可以做点什么与现有代码相似?谢谢你。
答案 0 :(得分:1)
您可以在初始化程序中调用render_file
方法。
def initialize(order)
super(top_margin: 50, size: 12)
@order = order
logo
# Other methods that generate pdf's content
footer
render_file "#{Rails.root}/public/uploads/orders/order-#{order.order_number}.pdf"
end