I've a rails controller that respond_to JSON with a wrong encoding. The site is correctly setup with UTF-8 encoding and the database as well. The text in my db is well formatted, but in the JSON response, all special characters are set to \ufffd. How can I solve the problem?
1 Answer
Everyone running on Ruby 1.9.x and using MySQL, should use the mysql2 gem. It forces the use of UTF-8 and converts to/from UTF-8 automatically when needed.
1 Comment
mikabytes
This did not work for me. I'm running Sqlite and characters are written/read from database correctly, however upon using the to_json method all special characters (such as 'åäöячщ') turns into \ufffd
encoding: utf8in yourdatabase.yml?