asalgan
asalgan

Reputation: 316

Rails CSV Upload Errors

I'm using active_admin_import to import CSV files into active_admin. When uploading the file, I keep getting a "CSV::MalformedCSVError" that states I have an Unclosed quoted field on line xx.

I checked that line, and every line around that line and there are no empty quotes anywhere near it. When I try deleting that line, the error then changes to "Unclosed quoted field on lie 415, and so on.

Error

Here is what my active_admin_import code looks like:

active_admin_import validate: false,
   on_duplicate_key_update: [:description, :price, :notes],
   ignore: [:name, :created_at, :updated_at]

Upvotes: 1

Views: 573

Answers (1)

asalgan
asalgan

Reputation: 316

If anyone stumbles on this, I realized upon converting my CSV to JSON I had a lot of "\r\n" (carriage return and line feed) showing up in my strings that wouldn't display in a CSV file. I got rid of them simply by running

mystr.gsub(/\r\n/," "))

and it removed these errors.

Upvotes: 1

Related Questions