Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSV.parse error undefined method `pos' for #<ActionDispatch::Http::UploadedFile:0x000001036cb6b0>

Maybe it's related to this issue: https://github.com/thoughtbot/paperclip/issues/issue/346

But in Rails 3.0.3 (ruby 1.9.2) I can't seem to get CSV.parse to work.

Here is sample code:

row_index = 0
CSV.parse(params[:dump][:file]) do |cells|
  column_index = 0
  cells.each do |cell|
    column_index += 1
  end
  row_index += 1
end
like image 888
Reed G. Law Avatar asked Nov 28 '22 18:11

Reed G. Law


1 Answers

I had to do this in Rails 3:

data = params[:dump][:file].read
CSV.parse(data)

params[:dump][:file] is an ActionDispatch object and can't be parsed directly by CSV.parse.

like image 106
Reed G. Law Avatar answered Dec 06 '22 23:12

Reed G. Law