[ACCEPTED]-invalid multibyte char (US-ASCII) with Rails and Ruby 1.9-ruby-1.9

Accepted answer
Score: 690

Have you tried adding a magic comment in 3 the script where you use non-ASCII chars? It 2 should go on top of the script.

#!/bin/env ruby
# encoding: utf-8

It worked 1 for me like a charm.

Score: 42

If you want to add magic comments on all 3 the source files of a project easily, you 2 can use the magic_encoding gem

sudo gem install magic_encoding

then just call magic_encoding in the terminal 1 from the root of your app.

Score: 18

I just want to add my solution:

I use german 6 umlauts like ö, ü, ä and got the same error.
@Jarek 5 Zmudzinski just told you how it works, but 4 here is mine:

Add this code to the top of 3 your Controller: # encoding: UTF-8
(for example to use flash 2 message with umlauts)

example of my Controller:

# encoding: UTF-8
class UserController < ApplicationController

Now 1 you can use ö, ä ,ü, ß, "", etc.

Score: 12

That worked for me:

$ export LC_ALL=en_US.UTF-8
$ export LANG=en_US.UTF-8

0

Score: 8

Those slanted double quotes are not ASCII 2 characters. The error message is misleading 1 about them being 'multi-byte'.

Score: 8

Just a note that as of Ruby 2.0 there is 2 no need to add # encoding: utf-8. UTF-8 is automatically 1 detected.

More Related questions