处理不兼容的字符编码:UTF-8和ASCII-8BIT [英] Dealing with incompatible character encodings: UTF-8 and ASCII-8BIT

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

问题描述

我在生产中遇到不兼容的字符编码错误。我试图在本地复制,但没有运气。这是错误讯息:

I am encountering an incompatible character encoding error in production. I tried to reproduce it locally but had no luck. This is the error message:

A ActionView::Template::Error occurred in controller_name#action_name:

 incompatible character encodings: UTF-8 and ASCII-8BIT
 activesupport (3.0.5) lib/active_support/core_ext/string/output_safety.rb:80:in `concat'

config.encoding 已在application.rb中设置为utf-8。对我来说,令人困惑的是,问题只持续一段时间,乘客重新启动,一段时间后消失。进一步调试异常backtrace给我这个:

config.encoding is already set to "utf-8" in application.rb. What's perplexing to me is that the issue persists only for some time around the Passenger restart and vanishes after some time. Further debugging into the exception backtrace gave me this:

activesupport (3.0.5) lib/active_support/core_ext/string/output_safety.rb:80:in `concat'
activesupport (3.0.5) lib/active_support/core_ext/string/output_safety.rb:80:in `concat'
actionpack (3.0.5) lib/action_view/template/handlers/erb.rb:14:in `<<'
app/views/web/controller_name/action_name.erb:98
<%currentUrl = request.url%>
Line 98: <a href="<%= raw currentUrl %>" id="xyz">

ActionView :: Template :: Error(不兼容的字符编码:UTF-8和ASCII-8BIT) ActionDispatch :: Request 可能会导致问题,但我无法确定问题如何解决自己一段时间后!

It is mentioned in "ActionView::Template::Error (incompatible character encodings: UTF-8 and ASCII-8BIT)" that ActionDispatch::Request might cause the problem, but I am clueless as to how the issue fixes itself after a while!

推荐答案

如果你得到这个错误与任何从数据库来的文本,那么你需要使用mysql2而不是mysql适配器在database.yml中。并在你的Gemfile中添加mysql2 gem。这将解决你的问题。

If you are getting this error with any text which is coming from database, then you need to use mysql2 in stead of mysql adapter in database.yml. And add mysql2 gem in your Gemfile too. This will solve your problem.

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

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