我正在使用Rails 4.1.2,以及gem 'activesupport-json_encoder', github: 'rails/activesupport-json_encoder'
和gem 'algoliasearch-rails'
。问题是,当我.to_json
在具有阿拉伯字符的ActiveRecord对象上调用on时,它将用替换任何阿拉伯字符�
。
> p = Product.find 100
#<Product id: 93038, name: "Men Jacket , front zipper, double colour light gre...", brand: "\xD8\xA7\xD8\xAE\xD8\xB1\xD9\x8A">
> puts p.to_json
{"id":93038,"name":"Men Jacket , front zipper, double colour light grey sizeXL","brand":"��������"}
我通过在https://github.com/rails/activesupport-json_encoder/blob/master/lib/active_support/json/encoding/active_support_encoder.rb#L127中强制使用“ utf-8”编码来解决此问题。我在这里https://github.com/mahmoud-abdelaziz/activesupport-json_encoder分叉了宝石。
通过添加gem 'activesupport-json_encoder', github: 'mahmoud-abdelaziz/activesupport-json_encoder'
,问题得以解决。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句