The following code snippet works fine for CSV file sizes larger than 10 K.
lines = CSV.read(open(resource.csv(:original)))
This is reading the the CSV file stored in Amazon S3 using Paperclip gem.
If the file size is smaller than 10 K however, I get the following error:
ActionView::Template::Error (can't convert StringIO into String):
I googled and found the following post:
http://adayinthepit.com/?p=269
So I tried to use the fastercsv gem, when I ran my program again, here is the error that I get:
ActionView::Template::Error (Please switch to Ruby 1.9's standard CSV library. It's FasterCSV plus support for Ruby 1.9's m17n encoding engine.):
Looks like it is a Catch-22. How can I process files smaller than 10 K in ruby 1.9.2 p290?
Please advise.
Thanks.
Bharat
I'm going to guess that CSV.read
is being handed a StringIO when it wants a String. If so, then you should be able to stick a read
call in and switch to CSV.parse
to make everyone happy:
lines = CSV.parse(open(resource.csv(:original)).read)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With