新手问题 ActionView::Template::Error (Your template was not saved as valid UTF-8.

brenda103 · 2016年01月04日 · 最后由 brenda103 回复于 2016年01月05日 · 2003 次阅读

将项目部署至另一服务器后,报错 (用 scaffold 建立的,index 的页面都正常显示,只有点击 new 页面会报此错误),报错信息如下所示:

  ActionView::Template::Error (Your template was not saved as valid UTF-8. Please either specify UTF-8 as the encoding for your template in your text editor, or mark the template with its encoding by inserting the following as the first line of the template:

# encoding: <name of correct encoding>.
The source of your template was:

3m�*��w��_v߃��޷p�#3ʱ���>�{nS�
���2��ȩWK�vJ|Dtt��TM�U�������T����3�a�D���ĉ�?p��m�S�,�:�iK,L�p;��'F�ex���<
    ��v�>/���%��_I�z�ö������v��Jj�
�zWE6��n$��ݴ��?u�n��R~���ȁ�=[r��k��$��f�o�Ӿ%p�d�uh69���MΏ��9�Wܦ^�X���¬ˆcZ~o���*�����V*�B��t�(一堆类似这样的乱码)

百度后发现一个解决此问题的帖子:

  1. 在文件头加上# encoding: utf-8

2.在 application.rb 文件里加上 config.encoding = "utf-8"

  1. 在 application.html.erb 文件里加上 但按此方法尝试,还是未能解决?请懂的朋友指点一二,小女子在此谢过!!

你的模板文件本身有米有用 utf-8 encoding 啊 查看试试

设置编辑器的保存编码为 utf8,如果编辑器没有这个设置,那么换一个编辑器。

#2 楼 @rei 谢谢回复,我把除了牵扯数据库的文件外全部替换了一次 就没有报错!用的 RubyMine

#1 楼 @edisonhsu 谢谢回复 好了!

需要 登录 后方可回复, 如果你还没有账号请 注册新账号