如何修复“不兼容的字符编码: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').