Ruby-on-rails Rails 3 无效的多字节字符(US-ASCII)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3916931/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Rails 3 invalid multibyte char (US-ASCII)
提问by framomo86
I found a similar post herebut 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 "è é "
我遇到了每个带有“èé”口音的“e”字符的问题
I tried to put magic comment # coding: utf-8but it doesnt work
我试图发表神奇的评论,# coding: utf-8但它不起作用
Any idea?
任何的想法?
回答by Johanisma
Instead of adding # coding: UTF-8try to add # encoding: UTF-8on the first line of the file.
而不是添加# coding: UTF-8尝试添加# encoding: UTF-8到文件的第一行。
It worked for me. I found the information here : http://groups.google.com/group/sinatrarb/browse_thread/thread/f92529bf0cf62015
它对我有用。我在这里找到了信息:http: //groups.google.com/group/sinatrarb/browse_thread/thread/f92529bf0cf62015
回答by Jimmy Huang
Just add the following line as the first line in the file:
只需将以下行添加为文件中的第一行:
# -*- coding: utf-8 -*-
and it will work.
它会起作用。
回答by RAJ
Add a magic comment in the script where you use non-ascii chars? It should go on top of the script.
在使用非 ascii 字符的脚本中添加魔术注释?它应该在脚本之上。
# encoding: utf-8
It worked for me like charm.
它像魅力一样对我有用。
Or if you want to make the project wide, you have an option of magic-encodinggem
或者,如果您想扩大项目范围,您可以选择使用魔法编码gem
回答by Kannan Natarajan
I changed the line:
我改变了线路:
gem 'pdf-writer', :git => 'git://github.com/metaskills/pdf-writer.git'
and that works for me.
这对我有用。
回答by Dario Chuquilla
Taken from http://devsolvd.com/questions/rails-3-invalid-multibyte-char-us-ascii
取自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
这对我很有用

