The code below checks and raises a Run Time error for unknown file formats.
def open_spreadsheet
case File.extname(file.original_filename)
when ".csv" then CSV.new(file.path)
when ".xls" then Roo::Excel.new(file.path, nil, :ignore)
when ".xlsx" then Roo::Excelx.new(file.path)
else
raise "Unknown file type: #{file.original_filename}"
end
end
I want to show the error message rather than runtime error.
attr_accessor :file
How can I validate the uploaded spreadsheet header field and show the error message if there is any modification in header from standard format?