Ruby on Rails:序列化UTF8问题
当我将包含 UTF8 字符串的哈希序列化时,如下所示:
poll.variants = {0 => 'тест',1 => '-тест-',2 => 'test # test "тест'}
到 ActiveRecord 字段,结果字段包含:
---
0: !binary |
0YLQtdGB0YI=
1: !binary |
LdGC0LXRgdGCLQ==
2: !binary |
dGVzdCAjIHRlc3QgItGC0LXRgdGC
由于某种原因,utf8 字符串被视为二进制和 base64 编码。 字段上的排序规则是 utf8_general_ci
,我有点失望。
有没有办法让 ActiveRecord :serialize 人类可读的 yaml 到现场?
When I serialize a hash containing UTF8 strings, like this:
poll.variants = {0 => 'тест',1 => '-тест-',2 => 'test # test "тест'}
to an ActiveRecord field, the resulting field contains:
---
0: !binary |
0YLQtdGB0YI=
1: !binary |
LdGC0LXRgdGCLQ==
2: !binary |
dGVzdCAjIHRlc3QgItGC0LXRgdGC
The utf8 strings get treated as binary and base64 encoded for some reason. The collation on the field is utf8_general_ci
, and I'm a bit disappointed.
Is there any way to make ActiveRecord :serialize human-readable yaml to the field?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不会。它采用 Base64 编码,以便将任意文本(以任何编码方式)编码为最低通用分母,然后可以安全地通过线路发送和/或存储在不接受 UTF-8 数据的数据存储中。
No. Its Base64 encoded so as to encode arbitrary text (in any encoding) down to the lowest common denonimator, which is then safe to send across the wire and/or store in datastores that dont accept UTF-8 data.