up

Resolve Ruby on Rails UTF-8 error message: invalid multibyte char (US-ASCII)

I got the following error when i run a rake db:seed command on may RoR application:
invalid multibyte char (US-ASCII)

I found the soution and the error has gone away:
You should add a line to your file:

# encoding: utf-8

You can change the utf-8 to any other encoding that you use.
I added this line to my seeds.rb file and all UTF-8 code have been executed without errors.

Update:
The good news: ruby 2.0+ has utf-8 default encoding. If you use 2.0 or newer you don't need to insert this line to your code.

Good luck!

Add new comment