Thoughts of a frozen geek

ArgumentError: invalid byte sequence in UTF-8

I came across this error while running my tests.

I am using Rails 3.0.3 + Ruby 1.9.2-p0 + RSpec 2.

The error ocurred when I tried to save some AR objects into my MySql database. The odd thing was that it only happened in 7 out of 10 times, or so. It was one those hard-to-trace errors.

The solution was to change my mysql adapter from mysql2 to ruby-mysql. Ruby-mysql is supposed to work better with Ruby 1.9 encodings.

So here is what I did:

1. Changed my Gemfile:

-gem 'mysql2'
+gem 'ruby-mysql'

2. Changed my config/database.yml

- adapter: mysql2
+ adapter: mysql

3. Ran "bundle install"

And that was all. After this change everything worked as expected.

0 comentarios:

Publicar un comentario