Forum: Ruby on Rails Question re: Charactersets

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
460ead051b49c0b2a8e45e46252d4bda?d=identicon&s=25 Tom Ha (tom)
on 2009-01-25 23:47
Hi there,

I need some help with characters (charactersets):

I have "special characters" in some db fields. When those fields are
used for the composition of an email, those "special characters" show up
screwed up in the email text, for example:

- a 'ü' in my db becomes a 'ü' in the email body.
- a 'é' in my db becomes a 'é' in the email body.

I suppose this has something to do with the choice of the charactersets,
but I don't know where the "bug" exactly lies...

in phpMyAdmin, I can see that
- MySQL charset:  UTF-8 Unicode (utf8)

Furthermore, I have set the following to "latin1_general_ci":
- MySQL connection collation
- the collation of the entire db
- the collation of all tables
- the collation of all columns (that have the type "varchar")

And: I used http://www.collation-charts.org/mysql60/ to check that my
charset/collation "latin1_general_ci" really *contains* the characters
needed (ö, ü, é, etc.), so I think that must be the right choice.

Thank you for any help with this!
Tom
460ead051b49c0b2a8e45e46252d4bda?d=identicon&s=25 Tom Ha (tom)
on 2009-01-26 00:38
Ok, here's the issue, in case anyone is interested
(internationalization...):

The email client used was Thunderbird. And Thunderbird uses by default
the following encoding:

Western ISO-8859
...also known as...
ISO 8859-2 Central European

So the MySQL db needed to use the same encoding or "the corresponding
collation" (which is "latin2_general_ci") in order to encode special
characters such as 'ü' or 'é' correctly.

(http://dev.mysql.com/doc/refman/5.1/en/charset-charsets.html)

Tom
460ead051b49c0b2a8e45e46252d4bda?d=identicon&s=25 Tom Ha (tom)
on 2009-01-26 01:48
Plus, the mailer model needed one more line:

def my_mail()
  charset    "latin1"     # -> tell it to use Western ISO-8859 encoding
!
  from       blah
  recipients blah
  subject    blah
  etc...
end
This topic is locked and can not be replied to.