2016-11-24 56 views
0

我下面的教程來填寫PDF和發送到瀏覽器...但出現錯誤:軌的respond_to pdf格式

ActionController::UnknownFormat (ActionController::UnknownFormat): 
    app/controllers/registries/customers_controller.rb:113:in `print_bollettino_2’ 

112 def print_bollettino_2 
113 respond_to do |format| 
114  format.pdf { send_file BollettinoUtente2Sezioni.new(@customer).export, type: 'application/pdf' } 
115 end 
116 end 

你能幫助我嗎?

非常感謝,

問候

回答

2

如果你會放一個format.pdfrespond_to,你需要通過添加爲新的格式申報config/initializers/mime_types.rb

Mime::Type.register "application/pdf", :pdf 

但你也可以實現它直接爲:

def print_bollettino_2 
    send_file BollettinoUtente2Sezioni.new(@customer).export, type: 'application/pdf' 
end 

您還可以使用:

send_data BollettinoUtente2Sezioni.new(@customer).export, type: 'application/pdf'

如果產生PDF的功能不返回文件路徑。