【问题标题】:Dealing with incompatible character encodings: UTF-8 and ASCII-8BIT处理不兼容的字符编码:UTF-8 和 ASCII-8BIT
【发布时间】:2013-11-19 15:38:54
【问题描述】:

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

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”。令我困惑的是,问题仅在乘客重新启动前后持续一段时间,并在一段时间后消失。对异常回溯的进一步调试给了我这个:

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 (incompatible character encodings: UTF-8 and ASCII-8BIT)”中提到ActionDispatch::Request 可能会导致问题,但我不知道问题如何在一段时间后自行解决!

【问题讨论】:

    标签: ruby-on-rails ruby utf-8 character-encoding passenger


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      尝试通过在文件顶部添加 # encoding: UTF-8 将文件编码设置为 UTF-8。

      【讨论】:

      • 我们已将编码强制为 UTF-8,并且可以正常工作。但是,仍然无法找出问题之前是如何解决的。
      猜你喜欢
      • 2011-07-14
      • 1970-01-01
      • 2011-10-17
      • 2011-05-26
      • 2011-12-14
      • 2016-04-27
      • 2012-07-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多