2014-12-05 59 views
0

我在Rails應用程序中使用惡毒的PDF生成PDF。這是由我的控制器中的一個私有函數generate_pdf完成的,因爲在購買過程中,我想生成該pdf,然後使用郵件函數將該pdf發送給用戶。在Rails應用程序中通過惡意pdf生成pdf文件時出現多個渲染錯誤

錯誤

Render and/or redirect were called multiple times in this action. Please note that you may only call render OR redirect, and at most once per action. Also note that neither redirect nor render terminate execution of the action, so if you want to exit an action after redirecting, you need to do something like "redirect_to(...) and return". 

代碼是騙人的東西這個。

def place_order 
... some code 

    download_new_pdf(@pur) 
    UserMailer.confirm_order(@pur).deliver 

    format.html { redirect_to(:action=>'order_confirmed/'[email protected][:id].to_s) } 
end 

和輔助功能將

def download_new_pdf(id) 

@my_ticket = Purchase.find(id) 
@event = Event.find(@my_ticket[:event_id]) 
render :pdf => "#{@my_ticket[:random_no]}.pdf", 
:template => 'tickets/download_invoice.html.erb', 
:save_to_file => Rails.root.join('public/data/docs', "#{@my_ticket[:random_no]}.pdf") 
end 

place_order會做所有的東西,DB和結束時生成PDF,發送郵件,並重定向到構象頁。但在這裏它給我多渲染

format.html { redirect_to(:action=>'order_confirmed/'[email protected][:id].to_s) } 

render :pdf => "#{@my_ticket[:random_no]}.pdf", 
    :template => 'tickets/download_invoice.html.erb', 
    :save_to_file => Rails.root.join('public/data/docs', "#{@my_ticket[:random_no]}.pdf") 

我試圖把和回報,但仍然沒有運氣錯誤堂妹,任何幫助,將不勝感激。謝謝 !!!

回答

0

您的錯誤很簡單。您在download_new_pdf中呈現並同時在place_order中重定向。它看起來像你需要創建PDF文件並存儲在文件系統中,而不是立即顯示給用戶,因此,請檢查readme,這裏解釋瞭如何創建PDF並且不將它呈現給客戶端