Chris
Chris

Reputation: 6611

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

Extracted source (around line #43):

40: <% if flash[:notice] -%>

41: <%=h flash[:notice] %>

42: <% end -%>

43: <%= yield :layout %>


Anyone can help me resolve this problem ?

Upvotes: 3

Views: 3563

Answers (3)

piffy
piffy

Reputation: 733

I found out that adding

# encoding: utf-8

at the beginning is much simpler (and possibly more elegant)

Upvotes: 2

okliv
okliv

Reputation: 3959

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)

Upvotes: 0

Preston Marshall
Preston Marshall

Reputation: 1195

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.

Upvotes: 0

Related Questions