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.