无法找出我的 Ruby 1.9 字符串编码在哪里被搞乱了
从数据库到应用程序的某个地方,这个:
sauté
正在变成这个:
sauté
我正在使用 Ramaze + Rack + MySQL。我设置了一个force_encoding插件,所以字符串的编码是UTF-8。如果我在数据库 shell 中查看记录,它看起来很好。表上的默认字符集是utf8,字段本身是“text”。我的数据库连接的编码是utf8。另外,在我的 Macbook 上,一切都运行良好。它在我的 Ubuntu 服务器上被破坏了。我希望有人能认识到这一点并告诉我这是 unicode 转换为 ASCII,然后又转换回来,或者类似的事情。
Somewhere along the line from the DB to the application, this:
sauté
is getting turned into this:
sauté
I'm using Ramaze + Rack + MySQL. I've got a force_encoding plugin set up, so the encoding on the string is UTF-8. If I view the record in the database shell, it's looks fine. The default charset on the table is utf8, and the field itself is "text". The encoding on my database connection is utf8. Also, on my Macbook, everything works great. It's on my Ubuntu server that it's getting mangled. I'm hoping that someone may recognize this and tell me that it's unicode getting turned to ASCII, then back, or something like that.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的区域设置很可能有所不同。
在两者上运行
locale
命令,看看有什么区别。我假设您在从 MySQL 返回结果时看到一个问题,根据 google 结果,这是 1.9 的常见问题: http://www.google.com/search?q=mysql+ruby+1.9+encoding。
Most likely your locale differs.
Run the
locale
command on both and see what's the difference.I assume you see an issue when you get results back from MySQL, which is a common issue with 1.9 according to google results: http://www.google.com/search?q=mysql+ruby+1.9+encoding.