Rails 3 编码::兼容性错误
我正在开发一个通过 ajax 提交法语翻译的 Rails 应用程序,由于某种原因,我不断在日志中收到以下错误:
Encoding::CompatibilityError 不兼容的字符编码:UTF-8 和 ASCII-8BIT
有谁知道如何解决这个问题?
修复:这适用于 WEBrick 服务器
将 #encode: UTF-8
放置在您想要使用不同字符的每个文件的顶部,
我无法让它在带有 Thin 的 Rails 服务器上工作。 ..还有其他人遇到这个吗?
I am working on a rails app that submits a french translation via ajax and for some reason I keep getting the following error in the log:
Encoding::CompatibilityError incompatible character encodings: UTF-8 and ASCII-8BIT
Does anyone know how to fix this?
FIX:This works on the WEBrick sever
Place # encode: UTF-8
at the top of each file you want to work with different chars
I can't get this to work on a rails server with Thin... anyone else run into this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
https://rails.lighthouseapp.com/projects/8994/tickets/4336-ruby19-subscribed-string-form-parameters-with-non-ascii-characters-cause-encoding-errors
以上链接解决了我的问题。
具体来说,在发送字符串进行翻译之前对其进行
myString.force_encoding('UTF-8')
处理。将示例代码放入 Application_controller.rb 文件中,一切顺利
https://rails.lighthouseapp.com/projects/8994/tickets/4336-ruby19-submitted-string-form-parameters-with-non-ascii-characters-cause-encoding-errors
the above link fixed my problem.
Specifically
myString.force_encoding('UTF-8')
on the string before sending it for translation.Placed the sample code in the Application_controller.rb file and all is well
我知道这已经很旧了,但我遇到了同样的问题,解决方案位于@dennismonsewicz 给出的链接中。详细来说,代码是:
是:
I know this is old, but I had the same problem and the solution was in the link @dennismonsewicz gave. In detail, the code was:
was:
我通过将 utf8 文件转换为 ascii 解决了这个问题。
请参阅此处的答案:ruby 1.9 + sinatra 不兼容的字符编码:ASCII-8BIT 和 UTF-8
I fixed this issue by converting an utf8 file to ascii.
See the answer here: ruby 1.9 + sinatra incompatible character encodings: ASCII-8BIT and UTF-8