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

Perhaps this is due to this problem: https://github.com/thoughtbot/paperclip/issues/issue/346

But in Rails 3.0.3 (ruby 1.9.2) I cannot get CSV.parse to work.

Here is a 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 
+4
source share
2 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 cannot be parsed directly by CSV.parse .

+20
source

Try to do

 CSV.parse(params[:dump][:file].tempfile).each do |row| #stuff with row end 

At least with Rails 3.2 and Ruby 1.9.2, this works.

+3
source

Source: https://habr.com/ru/post/1335116/


All Articles