mysql - 编码::UndefinedConversionError ("\xE2"(从 ASCII-8BIT 到 UTF-8):使用 Rails 4.1 和 mysql BLOB 数据类型

标签 mysql ruby-on-rails encoding utf-8

我正在使用 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.

The BLOB and TEXT Types

关于mysql - 编码::UndefinedConversionError ("\xE2"(从 ASCII-8BIT 到 UTF-8):使用 Rails 4.1 和 mysql BLOB 数据类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25434097/

相关文章:

php - 异步连接MySQL服务器

mysql workbench 如何更改下划线的列空格

ruby-on-rails - PostgreSQL 上的 Active Record 联合分组查询

c# - Ftp 使用 utf-8 字符创建一个文件名,例如希腊语、德语等

MySQL - 查询以更新具有外部引用值的所有行?

PHP MYSQL 搜索特定行

ruby-on-rails - 如何 'rake spec' 一个目录,例如楷模?

ruby-on-rails - mod_pagespeed 和 Rails - 它有什么改进吗?

excel - 我正在使用宏来进行邮件合并,如何在单词输出中保留中文数字?

html - CSS 没有加载到 Firefox 中?