Character Encoding w/ Padrino, AR, MySQL, and Ruby 1.9

Exceptions were occasionally occurring in Padrino: Encoding::CompatibilityError - incompatible character encodings: UTF-8 and ASCII-8BIT:. This is with Ruby 1.9.2. Googling the error message turned up plenty of hits, none of them helpful. Trying the same thing in the Padrino Framework Google Group was more helpful, but a key piece of information was missing. Or since the posts were a year and a half ago, things changed. The mysql gem encodes all strings as 8BIT ASCII! Even if the database is UTF-8. Switching to the msyql2 gem and setting the adapter to mysql2 in config/database.yml solved the problem. If your don’t set the adapter correctly, Padrino complains about stack too deep. I encountered the same stack overflow with ruby-mysql.

Leave a Reply

You must be logged in to post a comment.