2012-01-26 22 views
0

正如標題所說,我使用的Rails gem工作良好,但我想單獨將pdf保存到文件夾中。有沒有辦法做到這一點,而無需調用render_pdf?有沒有方法讓acts_as_flying_saucer在不調用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"} 

回答

0

的acts_as_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' } 
+0

謝謝,但我已經嘗試了所有的這些例子,但我需要的東西像這種情況:保存文件並重定向到另一頁。有趣的是,當我這樣做時,它抱怨我的meta標籤以正確的方式寫入,因爲該頁面在另一個使用send_file選項的頁面上工作。似乎飛碟庫lib也在驗證哪一個是好的,但是當它抱怨那些不存在或寫入正確的東西時。我將在此處編輯我的代碼以向您展示。 – MattiasB

+0

現在有效。我需要在render_pdf中使用:layout => nil。看到另一頁上。謝謝您的幫助。 – MattiasB

相關問題