1

I want to use comma OR semicolon as :col_sep when importing CSV data in rails:

CSV.foreach(file.path, :col_sep => (";"), headers: true) do |row|
  user_hash = row.to_hash
  User.create!(user_hash)
end

works. But putting different col_seps inline won't work:

CSV.foreach(file.path, :col_sep => (";",","), headers: true) do |row|

Is it even possible? I haven't found anything in the docu nor here on stackoverflow.

DonMB
  • 2,550
  • 3
  • 28
  • 59

1 Answers1

1

That isn't possible. Col_sep can only accept one string. There are workarounds for this, mentioned here and here.

Community
  • 1
  • 1
nesiseka
  • 1,268
  • 8
  • 22