[英]error: invalid byte sequence in UTF-8 after upgrading ruby 1.8.7 to ruby 1.9.2
I had my app running in ruby 1.8.7 and rails 3.0.11 ,I upgraded it with 1.9.2 ruby and rails 3.2.2. 我的应用程序在ruby 1.8.7和rails 3.0.11中运行,我用1.9.2 ruby和rails 3.2.2对其进行了升级。 it has a utf convertor like this 它有这样的utf转换器
@utf8_converter = Iconv.new('UTF-8//IGNORE', 'UTF-8')
......
......
def utf8(untrusted_string)
valid_string = @utf8_converter.iconv(untrusted_string + ' ')[0..-2]
return valid_string
Unto my Understanding Iconv doesn't support ruby 1.9.2. 据我所知Iconv不支持ruby 1.9.2。 how can make it run? 如何使其运行?
Thanks 谢谢
I believe this is should get you on the right track: 我相信这应该可以使您走上正确的轨道:
def utf8(untrusted_string)
valid_string = (untrusted_string + ' ').encode('utf-8')
return valid_string
end
The @utf8_converter
variable is no longer needed as Iconv is deprecated, so you can get away with just your utf8 method. 由于不推荐使用Iconv,因此不再需要@utf8_converter
变量,因此您可以只使用utf8方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.