2013-04-25 63 views

回答

9

原來的頁面有無效字符(一個間隔號「·」),我發現用下面的代碼(學分this gistthis question):

lines = IO.readlines("app/views/layouts/application.html.haml").map do |line| 
    line.force_encoding('ASCII-8BIT').encode('UTF-8', :invalid => :replace, :undef => :replace, :replace => '?') 
end 

File.open("app/views/layouts/application.html.haml", "w") do |file| 
    file.puts(lines) 
end 

運行此代碼後,我能找到一個簡單存在問題的字符3210並將代碼移到頂部有# encoding: utf-8的幫助程序文件中。 我不知道爲什麼這不與MRI的失敗,但它應該,因爲我沒有指定哈姆文件的編碼。