I spent some time today on a “hobby” (as Steve Jobs would say) that I’m incubating with a co-founder. Like my first and second startups, this one needs to be global.
Because this hobby is truly bootstrapped at the moment, I’m doing the database modeling and Rails code myself. I saw it didn’t take long for my brand new database to fill-up with funky characters like á, é and ú even though I had set my Rails application to UTF-8.
The solutions turns out to be pretty simple. If you’re developing a UTF-8 application in Rails, just make sure these two lines get added to the proper section(s) (development, production, test) of your database.yml:
encoding: utf8
collation: utf8_general_ci
Voila! All of your foreign language (and other UTF-8) symbols should go straight into MySQL without any weird encoding/decoding. Happy coding all you fellow weekend hackers!