Ruby on Rails: Fix for 'invalid multibyte char (US-ASCII)'
August 31, 2010
You probably got this error message in Ruby on Rails:
/Users/stefan/.../controllers/categories_controller.rb:37: invalid multibyte char (US-ASCII)
The problem is that Ruby 1.9 expects you to use ASCII characters in your source code, and you have used a non ASCII character. The solution is to tell Ruby that your source file is UTF-8 by including this directive as the first line of your file:
# encoding: utf-8
You probably use UTF-8 for all your files. Once you include a non-ASCII character, the difference between ASCII and UTF-8 becomes relevant for Ruby. That's when you need this directive.