I searched high and low for a simple solution. None of them were simple or “just worked.”
To get started, I keep getting this error:
ArgumentError: invalid byte sequence in US-ASCII
This is because users copy and paste content from Microsoft Word. I just want to be able to misinform user input so that it is stored in the database in the correct format, no matter what format they send me. Even if it completely destroys their contribution, I do not worry about it. I just want to make their contribution to something that I won’t complain about later.
I tried:
ic = Iconv.new('US-ASCII//IGNORE', 'US-ASCII')
safe_string = ic.iconv(unsafe_string)
After doing the above and saving a new line, the error still persists. I tried
safe_string = unsafe_string.force_encoding('US-ASCII')
Still giving me errors.
UTF-8. .
- , , ? .