Rails、IE、PostgreSQL、delayed_job 出现奇怪的 UTF-8 字节编码问题
我在 IE8、Rails 3.0.3、PostgreSQL 和delayed_job 的组合中看到一个相对奇怪(且难以诊断)的错误。
我的一个页面上有一个文本区域,在控制器中,我使用elasto_job延迟一条消息,其中包含一个具有文本区域内容的对象:
SomeMailer.delay.send_message(message)
这在Chrome、FF、Safari上运行良好。但是在 IE8 中仅,并且仅当我实际在文本区域中输入文本时,并且看起来只有当我在文本区域中输入回车符时(我认为) ,我从控制器收到此错误:
UTF-8 格式的字节序列无效
在我看来,当delayed_job 通过 ActiveRecord 将作业序列化到数据库时,它不喜欢换行符 (\r\n) 中的字符编码。这有点难以弄清楚,因为我不知道这是 IE、Rails、delayed_job 还是 Postgres 的问题。
旁注:我在本地收到此错误,但 Heroku 上似乎没有出现此错误 - 所以也许他们的数据库配置比我更好?
环境:
- Rails 3.0.3
- Ruby 1.9.2
- Postgres 8.4 - 编码 UTF8,排序规则 en_US.UTF-
- 8elasted_job 2.1.4
- IE 8
如有任何想法,我们将不胜感激。
I'm seeing a relatively strange (and hard to diagnose) error with a combination of IE8, Rails 3.0.3, PostgreSQL and delayed_job.
I have a text area on one of my pages, and in the controller I delay a message with delayed_job which includes an object which has the content from the text area:
SomeMailer.delay.send_message(message)
This works fine on Chrome, FF, Safari. However in IE8 only, and only when I actually enter text in the text area, and it looks like only when I enter a carriage return in the text area (I think), I get this error from the controller:
invalid byte sequence in UTF-8
This appears to me to be when delayed_job is serializing the job to the database via ActiveRecord, that it doesn't like the character encoding in the newline (\r\n). It's a bit hard to figure out because I don't know if this is an IE, Rails, delayed_job or Postgres issue.
Side Note: I'm getting this error locally, but it doesn't appear that this error appears on Heroku - so maybe they have their database configured better than I do?
Environment:
- Rails 3.0.3
- Ruby 1.9.2
- Postgres 8.4 - encoding UTF8, collation en_US.UTF-8
- delayed_job 2.1.4
- IE 8
Any thoughts would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否在发送到 IE8 的 HTML 中设置编码?例如:
其他浏览器可能正在解决丢失的信息,并在对文本区域中的数据进行编码时假设使用 UTF-8。
Are you setting your encoding in the HTML that is being sent to IE8? e.g.:
It's possible that the other browsers are working around the missing information and assuming UTF-8 when encoding the data from your text area.