0

I have a rails app where my users can manually set up products via a web form. This works fine and accepts foreign characters well, words like 'Svölk' for example.

I now have a need to bulk import products and am using FasterCSV to do so. Generally this works without issue, but when the CSV contains foreign characters it stalls at that point.

Am I correct to believe the file needs to be UTF-8 in the first instance?

Also, I'm running Ruby 1.8.7 so is ICONV my only solution for converting the file? This could be an issue as the format of the original file won't be known.

Have others encountered this issue and if so, how did you overcome it?

1 Answer 1

1

You have two alternatives:

  • Use ensure_encoding gem to find the actual encoding of the strings.
  • Use Ruby to determine the file encoding using:

File.open(source_file).read.encoding

I prefer the first approach as it tries to detected the encoding based on Strings, and tries to convert to your desired encoding (UTF-8) and then you can set the encoding on FasterCSV options.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks Paulo. I can't seem to get the ensure_encoding gem to work. It keeps giving me undefined method errors when I call it.
I also get and error on approach two: NoMethodError: undefined method `encoding'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.