开发者

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
开发者_开发技巧


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.


Try doing

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜