我正在使用wicked_pdf gem 生成一个 pdf 文件:
只有当对象被持久化/保存在数据库中时,我才想生成 pdf :
像这样的东西:
def new
@invoice = Invoice.new
respond_to do |format|
format.html # new.html.erb
end
end
def create
@invoice = Invoice.new(invoice_params)
respond_to do |format|
if @invoice.save
format.html { redirect_to invoice_path(@invoice), notice: "Yesss!") }
else
format.html { render action: new, :alert => "Oops :(" }
end
format.pdf do
@example_text = "exampletext"
render :pdf => "file_name",
:template => 'path/to/template'
end
end
end
但是这段代码只响应html。我想在里面生成pdf:
if @invoice.save
#generate the pdf here
format.html { redirect_to invoice_path(@invoice), notice: "Yesss!") }
else
我该怎么做,我可以使用回调吗?