I'm trying to upload a file using gem 'roo'. When I check for file of type, I have this in a instance method:
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
Is there a way to catch this exception so that user sees just message and gets to try again, without actually raising syntax error?