部署 [已解决] 部署服务器后报 ActionView::Template::Error (incompatible character encodings: ASCII-8BIT and UTF-8)

VincentJiang · 2015年08月20日 · 最后由 mimosa 回复于 2015年08月20日 · 2560 次阅读

在本地好好的,但部署服务器后就报:

I, [2015-08-20T05:34:47.927159 #4105]  INFO -- : Started GET "/about" for 218.17.158.154 at 2015-08-20 05:34:47 +0000
I, [2015-08-20T05:34:47.928334 #4105]  INFO -- : Processing by HomeController#about as HTML
I, [2015-08-20T05:34:47.929142 #4105]  INFO -- :   Rendered home/about.html.slim within layouts/application (0.0ms)
I, [2015-08-20T05:34:47.931840 #4105]  INFO -- :   Rendered share/_header.html.slim (1.7ms)
I, [2015-08-20T05:34:47.933189 #4105]  INFO -- : Completed 500 Internal Server Error in 5ms (ActiveRecord: 0.0ms)
F, [2015-08-20T05:34:47.934438 #4105] FATAL -- :
ActionView::Template::Error (incompatible character encodings: ASCII-8BIT and UTF-8):
    19:       = render 'share/header'
    20:       .vcontent
    21:         = flash_messages(:close, :fade)
    22:         = yield
    23:       = render 'share/footer'
    24:
    25:       a.to-top
  app/views/layouts/application.html.slim:22:in `_app_views_layouts_application_html_slim___2881078729979780413_26378660'

服务器是Ubuntu 14.04 LTS

请问有人有遇到过这种情况吗?

问题解决了。 原因是我手动在 mysql 里创建了数据库:

create database DATABASE_NAME;

导致编码不正确;

使用

RAILS_ENV=production rake db:create

就没有问题了。

# 解决 ArgumentError::InvalidByteSequence 错误
gem 'rack-utf8_sanitizer'
需要 登录 后方可回复, 如果你还没有账号请 注册新账号