# UTF-8 problems caching messing stuff up?

**URL:** <https://www.ruby-forum.com/t/utf-8-problems-caching-messing-stuff-up/48059>\
**Category:** Rails\
**Created:** [November 16, 2005, 12:27pm UTC](https://www.ruby-forum.com/t/utf-8-problems-caching-messing-stuff-up/48059 "2005-11-16T12:27:01Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jonte](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/6f9a4e/32.png) [@jonte](https://www.ruby-forum.com/u/jonte)\
**Post date:** [November 16, 2005, 12:27pm UTC](https://www.ruby-forum.com/t/utf-8-problems-caching-messing-stuff-up/48059/1 "2005-11-16T12:27:01Z")

</div>

Greetings Railers.

I have some problems to get my UTF-8 site to work correctly.  
Works fine under webrick and just after the reboot of lighttpd on  
production.

But on the next visit to the site, text fetched from the DB containing  
Ã?Ã?Ã? is replaced pÃ¥ “?”'s ☹

Done so far:  
_DB (MYSQL) \*  
charset set to UTF-8 on all tables.  
\*  
controllers/application.rb_  
before\_filter :set\_charset  
def set\_charset  
@headers[“Content-Type”] = “text/html; charset=UTF-8”  
end

suppress(ActiveRecord::StatementInvalid) do  
ActiveRecord::Base.connection.execute ‘SET NAMES UTF8’  
end

Could this be that the caching of the pages are non-utf8??  
Solution anyone?

Regards // Jonas Montonen

---

<div class="post-metadata">

**Author:** ![jonte](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/6f9a4e/32.png) [@jonte](https://www.ruby-forum.com/u/jonte)\
**Post date:** [November 16, 2005, 1:21pm UTC](https://www.ruby-forum.com/t/utf-8-problems-caching-messing-stuff-up/48059/2 "2005-11-16T13:21:20Z")

</div>

Andreas S. wrote:

> 

This does not help… The page is already sent in UTF-8 (Verified in  
Firefox, page info)

The problem is that some of the text (not hardcoded into the view) that  
are fecthed from the DB are messed up.  
Works after a restart of the server… but returns to ??? instead of  
Ã?Ã?Ã? after a while.

// Jonas

---

<div class="post-metadata">

**Author:** ![jonte](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/6f9a4e/32.png) [@jonte](https://www.ruby-forum.com/u/jonte)\
**Post date:** [November 16, 2005, 6:36pm UTC](https://www.ruby-forum.com/t/utf-8-problems-caching-messing-stuff-up/48059/3 "2005-11-16T18:36:11Z")

</div>

On Wed, Nov 16, 2005 at 01:07:01PM +0100, Andreas S. wrote:

> jonte wrote:
> 
> > Could this be that the caching of the pages are non-utf8??  
> > Solution anyone?

when the cache-files are written, it depends on the output of your  
webserver -

e.g. i had to put  
— snip —  
AddDefaultCharset UTF-8  
— snap —  
(beforehand the default output was iso8859-1)  
into apache-conf.

greetings

rene

---

<div class="post-metadata">

**Author:** ![jonte](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/6f9a4e/32.png) [@jonte](https://www.ruby-forum.com/u/jonte)\
**Post date:** [November 18, 2005, 7:11am UTC](https://www.ruby-forum.com/t/utf-8-problems-caching-messing-stuff-up/48059/4 "2005-11-18T07:11:50Z")

</div>

Rene P. wrote:

> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

I finally managed to locate the default charset option in Webmin (Hosted  
at [http://www.textdrive.com](http://www.textdrive.com))  
(Apache Server/Virtual Server XYZ/Languages/Character set for  
documents\*)\*.  
When I set that one to UTF-8 the caching seems to save my precious Ã?Ã?Ã?'s  
😉

Let’s see if it stays that way…

Thanks you all for the inputs!!  
Regards Jonas Montonen, [http://bytadvd.se](http://bytadvd.se)

---

<div class="post-metadata">

**Author:** ![jonte](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/6f9a4e/32.png) [@jonte](https://www.ruby-forum.com/u/jonte)\
**Post date:** [November 18, 2005, 1:08pm UTC](https://www.ruby-forum.com/t/utf-8-problems-caching-messing-stuff-up/48059/5 "2005-11-18T13:08:13Z")

</div>

Jonas Montonen wrote:

> > when the cache-files are written, it depends on the output of your webserver -  
> > rene
> 
> ## Regards Jonas Montonen, [http://bytadvd.se](http://bytadvd.se)
> 
> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

NOOOOO!!

It’s back!!

Well well… back to the drawing board.  
Using the plugin as well as UTF-8 as defaullt charset, still no party ☹  
// Jonas

---

<div class="post-metadata">

**Author:** ![jonte](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/6f9a4e/32.png) [@jonte](https://www.ruby-forum.com/u/jonte)\
**Post date:** [November 16, 2005, 5:05pm UTC](https://www.ruby-forum.com/t/utf-8-problems-caching-messing-stuff-up/48059/6 "2005-11-16T17:05:40Z")

</div>

On 16-nov-2005, at 13:19, Jonas Montonen wrote:

> that are fecthed from the DB are messed up.  
> Works after a restart of the server… but returns to ??? instead  
> of Ã?Ã?Ã? after a while.

You need to call “SET NAMES whatever” on every request.  
I recently wrote a little plugin which triggers all the needed hacks  
for Unicode for me.

---

<div class="post-metadata">

**Author:** ![jonte](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/6f9a4e/32.png) [@jonte](https://www.ruby-forum.com/u/jonte)\
**Post date:** [November 16, 2005, 1:07pm UTC](https://www.ruby-forum.com/t/utf-8-problems-caching-messing-stuff-up/48059/7 "2005-11-16T13:07:01Z")

</div>

jonte wrote:

> Could this be that the caching of the pages are non-utf8??  
> Solution anyone?

Appearantly the webserver doesn’t sent the correct content-type header.  
Try to set it in the HTML source with a meta tag:
