# Character encoding, MySQL, link\_to

**URL:** <https://www.ruby-forum.com/t/character-encoding-mysql-link-to/111203>\
**Category:** Rails\
**Created:** [August 3, 2007, 7:59pm UTC](https://www.ruby-forum.com/t/character-encoding-mysql-link-to/111203 "2007-08-03T19:59:33Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jrochkind](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/779978/32.png) [@jrochkind](https://www.ruby-forum.com/u/jrochkind)\
**Post date:** [August 3, 2007, 7:59pm UTC](https://www.ruby-forum.com/t/character-encoding-mysql-link-to/111203/1 "2007-08-03T19:59:33Z")

</div>

So, man, character encoding is confusing.

Worse, I’m talking to a vendor-supplied database (read-only) that I did  
not add the data too. At least this vendor-supplied database is MySQL.

So this database has some accented charactars in it. For instance,  
something as simple as a lowercase o with an acute accent, for example.

At first, this character was not being displayed correctly in my browser  
after being fetched from the db. Oddly, if I went into irb/console and  
examined the field from the db—it WAS displayed correctly in console!  
But in the browser, an o with an acute accent was displayed as two  
characters, neither of them right.

So, then I hit upon adding “encoding: utf8” to my information in  
databases.yml for this database. Now, magically, even though I still  
didn’t understand exactly what was going on—it displayed properly in  
my browser when fetched from the db, and then put in a view with \<% =.  
But, now it displayed _incorrectly_ in console!

Completely not understanding what was going on, I didn’t worry about it  
much, because after all, it was working.

Until I needed to put such a string fetched from the db in a GET url  
parameter. So I add it to a hash, and call link\_to. And an o with an  
acute accent (one single character) ends up getting encoded in the URL  
as:  
%C3%B3

And on the other end when ruby decodes it again, it’s again two wrong  
characters, not an o with an acute accent. Specifically, it’s (let’s see  
if this comes through the listserv): ÃƒÂ³

Can anyone help me figure out what the heck is going on, and how to fix  
it? I need to get this stuff out of MySQL, I need to display it properly  
in the browser, AND I need to be able to encode it properly as a URL GET  
param. It may very well be a problem in the data in the vendor supplied  
database, but I’m just confused at this point.
