Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3 invalid multibyte char (US-ASCII)

I found a similar post here but I can't solve the problem anyway.

I got this

/home/fra/siti/Pensiero/db/seeds.rb:32: invalid multibyte char (US-ASCII)
/home/fra/siti/Pensiero/db/seeds.rb:32: invalid multibyte char (US-ASCII)
/home/fra/siti/Pensiero/db/seeds.rb:32: syntax error, unexpected $end, expecting ')'
... ed il valore della vita, si è malati", :user_id => 1, :cat...

The problem is in this string

:body => "Nel momento in cui ci si chiede il significato ed il valore della vita, si è malati"

I got the problem with every "e" character with the accent, like "è é "

I tried to put magic comment # coding: utf-8 but it doesn't work.

Any idea?

like image 969
framomo86 Avatar asked Oct 12 '10 16:10

framomo86


4 Answers

Instead of adding # coding: UTF-8 try to add # encoding: UTF-8 on the first line of the file.

It worked for me. I found the information here : http://groups.google.com/group/sinatrarb/browse_thread/thread/f92529bf0cf62015

like image 120
Johanisma Avatar answered Oct 21 '22 02:10

Johanisma


Just add the following line as the first line in the file:

# -*- coding: utf-8 -*-

and it will work.

like image 42
Jimmy Huang Avatar answered Oct 21 '22 02:10

Jimmy Huang


Add a magic comment in the script where you use non-ascii chars? It should go on top of the script.

# encoding: utf-8

It worked for me like charm.

Or if you want to make the project wide, you have an option of magic-encoding gem

like image 6
RAJ Avatar answered Oct 21 '22 02:10

RAJ


I changed the line:

gem 'pdf-writer', :git => 'git://github.com/metaskills/pdf-writer.git'

and that works for me.

like image 1
Kannan Natarajan Avatar answered Oct 21 '22 03:10

Kannan Natarajan