While debugging my Rails App I found the following messages in the log file:
(0.1ms) ROLLBACK
Completed 500 Internal Server Error in 25ms (ActiveRecord: 4.2ms)
ActiveRecord::StatementInvalid (Mysql2::Error: Incorrect string value: '\xF0\x9F\x98\x89 u...' for column 'description' at row 1: INSERT INTO `course` (`title`, `description`) VALUES ('sometitle', '<p>Description containing and stuff</p>')
This seems to stem from my database being MySQL with not-quite-utf-8:
CREATE TABLE `course` (
`id` int NOT NULL AUTO_INCREMENT,
`title` varchar(250) DEFAULT NULL,
`description` text,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2080 DEFAULT CHARSET=utf8;
According to the answers to this question CHARSET=utf8 is only capable of handling 3 byte characters, not 4 byte characters.
The Emoticon needs four bytes - see \xF0\x9F\x98\x89 in the log file.
I am wary of converting the whole database. I would rather forbid the use of emoticons and other 4 byte characters - they are really not necessary on my site.
What is the best way to do this in Rails?