# Rendering exotic character

**URL:** <https://www.ruby-forum.com/t/rendering-exotic-character/116301>\
**Category:** Rails\
**Created:** [October 4, 2007, 11:05am UTC](https://www.ruby-forum.com/t/rendering-exotic-character/116301 "2007-10-04T11:05:54Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tarscher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/8491ac/32.png) [@Tarscher](https://www.ruby-forum.com/u/Tarscher)\
**Post date:** [October 4, 2007, 11:05am UTC](https://www.ruby-forum.com/t/rendering-exotic-character/116301/1 "2007-10-04T11:05:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Tarscher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/8491ac/32.png) [@Tarscher](https://www.ruby-forum.com/u/Tarscher)\
**Post date:** [October 4, 2007, 11:41am UTC](https://www.ruby-forum.com/t/rendering-exotic-character/116301/2 "2007-10-04T11:41:02Z")

</div>

On 10/4/07, Tarscher [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 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?

> **[The Absolute Minimum Every Software Developer Absolutely, Positively Must...](https://www.joelonsoftware.com/2003/10/08/the-absolute-minimum-every-software-developer-absolutely-positively-must-know-about-unicode-and-character-sets-no-excuses/)**
>
> Ever wonder about that mysterious Content-Type tag? You know, the one you’re supposed to put in HTML and you never quite know what it should be? Did you ever get an email from your friends in…

Sincerely,  
Isak

---

<div class="post-metadata">

**Author:** ![Tarscher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/8491ac/32.png) [@Tarscher](https://www.ruby-forum.com/u/Tarscher)\
**Post date:** [October 4, 2007, 2:53pm UTC](https://www.ruby-forum.com/t/rendering-exotic-character/116301/3 "2007-10-04T14:53:51Z")

</div>

On 10/4/07, Tarscher [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 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.

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.

---

<div class="post-metadata">

**Author:** ![Tarscher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/8491ac/32.png) [@Tarscher](https://www.ruby-forum.com/u/Tarscher)\
**Post date:** [October 8, 2007, 2:44pm UTC](https://www.ruby-forum.com/t/rendering-exotic-character/116301/4 "2007-10-08T14:44:09Z")

</div>

Many thanks for the reply. It’s still not clear thuogh.

My page that renders the questionmark has:

 ...

Shouldn’t that be sufficient to render the exotic caracter?

Regards,  
Stijn

---

<div class="post-metadata">

**Author:** ![Tarscher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/8491ac/32.png) [@Tarscher](https://www.ruby-forum.com/u/Tarscher)\
**Post date:** [October 8, 2007, 6:14pm UTC](https://www.ruby-forum.com/t/rendering-exotic-character/116301/5 "2007-10-08T18:14:34Z")

</div>

On 10/8/07, Tarscher [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Many thanks for the reply. It’s still not clear thuogh.
> 
> My page that renders the questionmark has:
> 
> ...
> 
> Shouldn’t that be sufficient to render the exotic caracter?

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?

---

<div class="post-metadata">

**Author:** ![Tarscher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/8491ac/32.png) [@Tarscher](https://www.ruby-forum.com/u/Tarscher)\
**Post date:** [October 8, 2007, 5:00pm UTC](https://www.ruby-forum.com/t/rendering-exotic-character/116301/6 "2007-10-08T17:00:33Z")

</div>

Tarscher wrote:

> Many thanks for the reply. It’s still not clear thuogh.
> 
> My page that renders the questionmark has:
> 
> ...
> 
> Shouldn’t that be sufficient to render the exotic caracter?

Is the character in a variable or hardcoded in the template? If it’s  
hardcoded, you need to ensure your editor is saving your template as  
UTF-8. If it’s a variable, you need to ensure you have all the Ruby  
I18N configuration set up correctly for UTF-8.
