熊猫家族博客新版本上线,欢迎大家交流

Redmine incompatible character encodings UTF-8 and ASCII-8BIT

###异常信息 After migrating Redmine to a new server, I’ve encountered such an error:

ActionView::Template::Error (incompatible character encodings: ASCII-8BIT and UTF-8):
    55:         <%= yield :sidebar %>
    56:         <%= view_layouts_base_sidebar_hook_response %>
    57:     </div>
    58: 
    59:     <div id="content">
    60:         <%= render_flash_messages %>
    61:         <%= yield %>
  app/views/layouts/base.html.erb:58:in `_app_views_layouts_base_html_erb__1607427593261861101_37006840

###解决方案 1、Make sure config.encoding = “utf-8” is in the application.rb file.
2、Make sure config.encoding = “utf-8” is in the application.rb file.
3、Make sure you are using the ‘mysql2’ gem.
4、Put # encoding: utf-8 at the top of file containing UTF-8 characters.
5、Above the ::Application.initialize! line in the environment.rb file, add following two lines:

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

6、make database.yml config

production:
  adapter: mysql2
  database: redmine
  host: localhost
  username: root
  password: "123456"
  encoding: utf8

注意:adapter: mysql2 必须是mysql2,如果使用mysql则就会出现上面的问题
7、locale确认操作系统的编码是否UTF-8

LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE=zh_CN.UTF-8
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=

可以设置下操作系统的编码

vi ~/.bashrc或者/etc/profile
export LANGUAGE=en_US.UTF-8
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8