Rails 3 invalid multibyte char (US-ASCII)

社会主义新天地 提交于 2019-12-17 10:19:51

问题


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 into this string

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

I got the problme with every "e" charachter with the accent like "è é "

I tried to put magic comment # coding: utf-8 but it doesnt work

Any idea?


回答1:


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




回答2:


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

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

and it will work.




回答3:


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




回答4:


I changed the line:

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

and that works for me.




回答5:


Taken from http://devsolvd.com/questions/rails-3-invalid-multibyte-char-us-ascii

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

This was useful for me



来源:https://stackoverflow.com/questions/3916931/rails-3-invalid-multibyte-char-us-ascii

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!