7

I receive "incompatible character encodings: CP850 and UTF-8" when displaying the £ symbol on my ramaze app. How can I get rid of this error? I have the UTF-8 meta tag in my head tag.

It happens when I type the £ symbol with the keyboard. Look.

encoding error

I have put the following code in my ruby file and it hasn't fixed the problem.

# encoding: UTF-8 
Encoding.default_external = 'utf-8'
Encoding.default_internal = Encoding::UTF_8
desbest
  • 4,746
  • 11
  • 51
  • 84

3 Answers3

4

Try to force the encoding to see if that makes the problem go away:

your_string.force_encoding(::Encoding::UTF_8)

If it does, dive into your app and spot what is setting the wrong encoding, where, and why.

It's possibly server-/webpage-related, as in the page you're serving is rendered as US-ASCII owing to a header. Or the server is started with encoding other than UTF-8. Or something other to that effect. Your script ends up with a piece of external data that isn't UTF-8.

Denis de Bernardy
  • 75,850
  • 13
  • 131
  • 154
  • Your line of code doesn't work. I tried this answer but it didn't work as I didn't have the `LC_ALL` variable defined on my computer. http://stackoverflow.com/questions/5908774/set-global-default-encoding-for-ruby-1-9/17616076#17616076 – desbest Aug 14 '15 at 10:47
1

Windows issue? Try using Iconv:

Iconv.conv('utf-8', "WINDOWS-1253", X)

Robert Pounder
  • 1,490
  • 1
  • 14
  • 29
0

You must convert the text from UTF-8 to another encoding and then back to UTF-8.

content = content.force_encoding("ISO-8859-1").encode("utf-8", replace: nil)

Update: This answer didn't work for me, but it might help you.

desbest
  • 4,746
  • 11
  • 51
  • 84