我正嘗試使用gem'roo'上傳文件。當我檢查類型的文件,我有這樣一個實例方法:如何在Rails應用程序中引發錯誤?
def open_spreadsheet
case File.extname(file.original_filename)
when ".xls" then Roo::Excel.new(file.path, file_warning: :ignore)
when ".xlsx" then Roo::Excelx.new(file.path, file_warning: :ignore)
when ".csv" then Roo::CSV.new(file.path, file_warning: :ignore)
when ".ods" then Roo::LibreOffice.new(file.path,file_warning: :ignore)
else raise "Unknown file type"
end
end
有沒有辦法讓用戶看到的只是信息,並得到再次嘗試,實際上並沒有提高語法錯誤捕獲此異常?
這是在控制器中嗎? – Jon 2015-02-23 14:09:19
什麼?這種方法?不,它在模型中。 – ivanacorovic 2015-02-23 14:17:16