Skip to content


Ruby on Rails: Fix for ‘invalid multibyte char (US-ASCII)’

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.

Posted in Ruby on Rails.


One Response

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. niyazi says

    HELP : linuxmint “katya”+ruby1.9+rails+sqlite3 … the problem is “turkish” characters error like “ı ş ç ö ğ ü ” not display in browser with webrick server… is there any gem for turkish character set ?
    you said,
    # encoding : utf-8
    where i have to add this line?
    thanks



Some HTML is OK

or, reply to this post via trackback.