开发者

Parsing YAML Rails fails with UTF8 problems, IRB does fine?

开发者 https://www.devze.com 2023-04-05 04:18 出处:网络
i currently try to import some XML via XMLSimple in my RoR-3 App. on 1 position, that XML stores a YAML-Structure. Dont slap me, i did not create the xml ;)

i currently try to import some XML via XMLSimple in my RoR-3 App.

on 1 position, that XML stores a YAML-Structure. Dont slap me, i did not create the xml ;)

now that i have it stored in a variable, lets say yamldata, i want to parse its content.

so i do:

chunks = YAML::load yamldata

and thats pretty it.

when i now echo these chunks-values to console, it get this:

  • Bülach vert

what i wanted to have is:

  • Bülach vert

when i use exact same sourcecode in IRB, i actually get this 'ü' instead of 'ü'.

i really dont know what to do here.


my Gemfile:

cat Gem开发者_Python百科file

source 'http://rubygems.org'

gem 'rails', '3.1.0'
gem 'mysql2'
gem 'haml'
gem 'activerecord', :require => "active_record"
gem 'xml-simple'
gem 'hpricot'

ruby -v: ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-linux]

i`d be happy with any idea.

Note: i echo these values before!! i store them into a model, so i guess that its not a sql-related issue - however, db-encoding is utf8 too.

any idea? Thanks!

thanks to the helpers! :)


i found that irb does use Syck, rails Psych. so i guess this is the main difference... will research more..

SOLUTION:

 require 'yaml'
 YAML::ENGINE.yamler= 'syck'

into boot.rb and BAM!


Maybe this answer can help you:

Ruby on Rails 3, incompatible character encodings: UTF-8 and ASCII-8BIT with i18n

He states that he could solve a similar problem by configuring this:

Encoding.default_external = Encoding::UTF_8
Encoding.default_internal = Encoding::UTF_8

on config/environment.rb

Hope that helps.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号