问题
I get this error when writing to database:
Encoding::UndefinedConversionError "\xD0" from ASCII-8BIT to UTF-8
After googling around a bit the problem seems to lie in ruby 1.9.2 string handling but no real solution found.
I use magic_encoding to force utf-8 on all data. My database runs on utf-8 as well.
I'm running rails 3.1 and ruby 1.9.2.
Anyone that can shine some light on this error?
回答1:
You should add this line to the top of your .rb file
# encoding: utf-8
Or you can use this gem
magic_encoding
Related topic:
Add "# coding: utf-8" to all files
来源:https://stackoverflow.com/questions/7632473/encoding-error-while-writing-data-from-excelfile-to-database-mysql