如何修复“不兼容的字符编码:UTF-8和ASCII-8BIT”? [英] How do I fix "Incompatible character encodings: UTF-8 and ASCII-8BIT"?

查看:184
本文介绍了如何修复“不兼容的字符编码:UTF-8和ASCII-8BIT”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


不兼容的字符编码:UTF-8和ASCII-8BIT

Incompatible character encodings: UTF-8 and ASCII-8BIT

我如何解决这个错误在Rails 3.2.3和Ruby 1.9.3?

How can I solve this error on Rails 3.2.3 and Ruby 1.9.3?

我试图把这两行放在environment.rb中:

I tried to put these two lines in the environment.rb:

Encoding.default_external = Encoding::UTF_8
Encoding.default_internal = Encoding::UTF_8

我确定application.rb还包含这行 config.encoding =utf-8

I am sure that application.rb also contains this line "config.encoding = "utf-8".

有谁知道如何解决这个问题?

Does anyone know how to solve this?

推荐答案

存储在hdd上,您可以尝试 data.force_encoding('UTF-8')

If you have data to store on the hdd, you can try data.force_encoding('UTF-8').

这篇关于如何修复“不兼容的字符编码:UTF-8和ASCII-8BIT”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆