In my rails app I am using Roo to process spreadsheet and I want to handle TypeError exception if the file is not a spreadsheet.
begin
xls = Roo::Excelx.new(@file_upload.file.path)
rescue TypeError
return redirect_to students_url, :flash => { :error => t("wrong_file_format") }
end
How do I add a case that also tries if the file is an open office?
xls = Roo::OpenOffice.new(@file_upload.file.path)
This can be done conveniently by basing the decision on the file extension.
I hope I got the extensions right. If not, you can easily modify them in the code.