Rails和html - 编码错误

时间:2011-07-18 09:43:29

标签: ruby-on-rails utf-8

我的模板中的

(index.html.erb)对于任何代码(如utf-8或其他任何代码)都没有。 因此铁路当然有问题。

    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>.

所以我试着把它粘贴到我的html中: # encoding: < meta charset=utf-8 />.

我写错了吗?或者我可以采取任何其他代码吗?

rails的答案是:unknown encoding name - <

感谢您的回答

5 个答案:

答案 0 :(得分:4)

检查文件本身是否保存为UTF-8。

这是我的问题。

使用“e”作为texteditor或Notepad ++(或任何其他(windows)工具)配置错误可能是问题所在。

e(我认为Notepad ++)配置为将文件保存为“Windows DOS OEM(EP 437)”。

我在设置中将其更改为UTF-8,已保存的alle文件(有更改)并且有效。

答案 1 :(得分:3)

你的application.rb文件中的

粘贴了这一行

config.encoding = "utf-8"

或在您的application.html.erb文件中粘贴以下行

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

答案 2 :(得分:1)

元字符集适用于HTML。你需要为ruby指定charset,你可以使用这样的注释来实现:

# encoding: utf-8

答案 3 :(得分:0)

使用Rubymine4,意外地右键单击并没有看到我按下了什么......砰!代码=走了!加1错误!我已经将页面重新编码为一些疯狂的编码。只需右键点击页面即可 - &gt;用另一种编码保存'[你的疯狂编码在这里]'文件。

Rubymine,太容易了! ;)

答案 4 :(得分:0)

这解决了我。毕竟,我的文件没有被保存为utf-8。

https://superuser.com/questions/581553/sublime-text-2-encoding-utf-8