Over the last years some of my clients created error tickets about problems when saving texts with special characters like arrows in headlines etc. . Most of them were caused by classic Mysql2::Error: Incorrect string value
- exceptions. First I thought the texts were c&p from places with incompatible encodings or include control characters.
While investigating another database related problem lately I found this blog entry by Mathias Bynens https://mathiasbynens.be/notes/mysql-utf8mb4
It says that MySQL by default doesn't use the full unicode charset and shows a detailed instruction how to enable it. The alternative title says: The things we do to store U+1F4A9 PILE OF POO (💩
) correctly.
All you have to do, is to change the database (and table and column) encoding from plain utf8 to utf8mb4 and adjust your database.yml
encoding: utf8mb4
collation: utf8mb4_bin