exception - Rescue won't rescue in Rails -


i'm writing simple app processes posted csv files , testing against invalid input (e.g. non-csv files). i'm using csv::reader.parse command parse csv in controller method, follows:

@parsed_file = csv::reader.parse(params[:file]) rescue [] 

however, despite rescue statement, i'm still getting uncaught csv::illegalformaterror when improper submissions entered. missing here?

thanks!

you need pass file handle parse:

@parsed_file = csv::reader.parse(file.open(params[:file], 'rb')) rescue [] 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -