我正在使用 rails 4.1 和 mysql。
在列的数据库表中,我有一个 blob 数据类型,其中我正在保存新闻报纸文章,但是在获取索引操作中的所有内容时,我遇到了以下错误。
Encoding::UndefinedConversionError ("\xE2" from ASCII-8BIT to UTF-8):
我尝试了网上很多解决方案,但无法解决问题。
* before_save { self.article =article.encode('utf-8', :invalid => :replace, :undef => :replace, :replace => '_')}* 等等..
非常感谢您的帮助..谢谢
最佳答案
仅供引用..已解决,我将数据类型从 BLOB 更改为 TEXT 并且有效。
BLOB values are treated as binary strings (byte strings). They have no character set, and sorting and comparison are based on the numeric values of the bytes in column values. TEXT values are treated as nonbinary strings (character strings). They have a character set, and values are sorted and compared based on the collation of the character set.
关于mysql - 编码::UndefinedConversionError ("\xE2"(从 ASCII-8BIT 到 UTF-8):使用 Rails 4.1 和 mysql BLOB 数据类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25434097/