有没有办法让acts_as_flying_saucer在不调用render_pdf的情况下保存文件?

时间:2012-01-26 14:57:14

标签: ruby-on-rails pdf pdf-generation flying-saucer

正如标题所说,我使用的Rails gem工作正常,但我想单独将pdf保存到文件夹中。有没有办法在不调用render_pdf的情况下执行此操作?

这是行不通的:

  render_pdf :template => 'caseprinttemplates/create_pdf_to_print.erb', :pdf_file => "/home/mattias/www/Inkasso/public/uploadedfiles/" + results[:title]

  redirect_to new_interventionreminder_path(:case_id => @interventionreminder.case_id, :saved => "1")
  return

这适用于其他页面:

render_pdf :template => 'caseprinttemplates/create_pdf_to_print.erb', :layout => nil, :send_file => { :filename => "samladutskrift.pdf"}

1 个答案:

答案 0 :(得分:0)

acts_as_flying_saucer插件只是Flying Saucer java库的包装器。在源代码中,您可以看到只定义了一个包装器方法:render_pdf()。

https://github.com/dagi3d/acts_as_flying_saucer/blob/master/lib/acts_as_flying_saucer_controller.rb

但是,您可以使用render_pdf()渲染文件,例如找到的示例here

# Renders the template located at '/foo/bar/pdf.html.erb' and stores the pdf 
# in the temp path with a filename based on its md5 digest
render_pdf :file => '/foo/bar/pdf.html.erb'

# renders the template located at 'app/views/foo.html.erb' and saves the pdf
# in '/www/docs/foo.pdf'
render_pdf :template => 'foo', :pdf_file => '/www/docs/foo.pdf'

# renders the 'app/views/foo.html.erb' template, saves the pdf in the temp path
# and sends it to the browser with the name 'bar.pdf'
render_pdf :template => 'foo', :send_file => { :filename => 'bar.pdf' }