How to deal with 'incompatible character encodings: ASCII-8BIT and GBK' exception?
I am reading 'Agile Web Development with Rails.3rd'. When finishing the depot application, I input some Chinese character as user name. But I got this error, it seems this has something to do with Ruby1.9
My environment is window xp, Ruby1.9 Rails 2.3.8 and sqlite3.
The following is the detail about this error:
Showing app/views/layouts/store.html.erb where line #43 raised:
incompatible character encodings: ASCII-8BIT and GBK
Ext开发者_如何学Cracted source (around line #43):
40: <% if flash[:notice] -%>
41: <%=h flash[:notice] %>
42: <% end -%>
43: <%= yield :layout %>
Anyone can help me resolve this problem ?
I found out that adding
# encoding: utf-8
at the beginning is much simpler (and possibly more elegant)
You might try putting this in your environment.rb file:
Encoding.default_internal = Encoding.find("UTF-8")
You might also be compounding the problem with incorrect console encoding in Windows. Make sure it is set to Unicode.
it's ridiculous but i had the same issue until
i found that i just had cyrillic "C" in the one of the classes name %)
so maybe it is good advice to check if you not using something like c, a, o, p etc from another keyboard layout(s)
精彩评论