incompatible character encodings: UTF-8 and ASCII-8BIT
I'm finding lots of old information yet scant advice about this error message but wondered what the current status is as there seems to be less discussion of it around the net. It occurs for me when I try to render text from a locale file that includes accented characters, for example 'é'.
I'm using rails 3.0.3, ruby 1.9.2 (and have tried 1.8.7 with same result), mysql2 adapter, utf8 encoding.
For the time being, this can be caused by an issue in Mail 2.5.4, which 'pollutes' the encoding of the mail object.
I remember resolving this once by using "string".force_encoding("UTF-8")
I've gotten this error when there is an encoding mismatch between how my Ruby app is parsing strings and how the database stores them.
To fix this for myself when I'm dealing with UTF-8, I make sure I have this at the top of the .rb file in question:
Alternatively, you can globally set default UTF-8 encoding in your application config file with this line:
And finally, I make sure that my database is using UTF-8 internally by setting the
encoding
option in database.yml: