存储在 Rails 数据库中的文本在电子邮件中显示有趣(文本和 HTML)

Text stored in Rails DB showing funny in emails (both text and HTML)

我很难过。假设存储在数据库中的文本是这样的:

none of those had handles... @Bobby isn't that wild... 

这正是我 运行 Model.first.property_name 时它在控制台中的显示方式。这就是我想在电子邮件中显示的内容。

现在,当我通过 <%= @instance.property_name %> 将其插入电子邮件模板时,我的 HTML 和 TEXT 电子邮件显示如下:

none of those had handles... @Bobby=C2=A0isn't that wild...= =C2=A0

知道这里发生了什么吗?我可以做些什么来按应有的方式显示文本?

你有一个意想不到的 Unicode non-breaking space somewhere. A non-breaking space in UTF-8 consists of the bytes \xC2 and \xA0 in that order. That character (which is two bytes long) will appear as =C2=A0 in the MIME quoted-printable 表述。

在视图中修复您的 spaces(如果那是杂散的 space 所在的位置)或正确剥离您的传入属性(如果那是杂散的 space 的来源).