hi all,
I put a ° in a string but when I render it to the screen the ° changes in <?> block. The rest of the string is renderen correctly.
How is this caused?
Thanks Stijn
hi all,
I put a ° in a string but when I render it to the screen the ° changes in <?> block. The rest of the string is renderen correctly.
How is this caused?
Thanks Stijn
hi all,
I put a ° in a string but when I render it to the screen the ° changes in <?> block. The rest of the string is renderen correctly.
How is this caused?
Sincerely, Isak
By default, Rails tells the browser that the content type for your pages is UTF-8. If your templates are using a different encoding, that will cause the problem you're seeing.
Many thanks for the reply. It's still not clear thuogh.
My page that renders the questionmark has: <head> <meta http-equiv="content-type" content="text/html;charset=UTF-8" /> ...
Shouldn't that be sufficient to render the exotic caracter?
Regards, Stijn
No, not if the character is not actually UTF-8. Your editor has to be saving as UTF-8 as well.
Let's look at the "degree" character:
The Unicode code point is 0176 decimal (hex 00B0).
The Latin1 encoding is one byte: 0xB0
However, the UTF-8 encoding is *two* bytes: C2 B0
Now, suppose your editor is set to use Latin1. You will see a degree character on the screen in your editor. When you save the file, the editor will write this a a single 0xB0 byte (since that's how you represent this symbol in Latin1 encoding).
Now, when the template gets sent to the browser, you've told it that you're sending UTF-8. As the data is sent, the browser tries to interpret the 0xB0 as a UTF-8 sequence and it gets confused, because 0xB0 is not a legal UTF-8 sequence. So, since it doesn't know what you're trying to do, it shows a question mark or some other marker character.
Make sense?