I'm using Rails 4.1.2, along with gem 'activesupport-json_encoder', github: 'rails/activesupport-json_encoder'
and gem 'algoliasearch-rails'
. The problem is when i call the .to_json
on on ActiveRecord object that have Arabic characters, it replaces any Arabic characters with �
.
> 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":"��������"}
I fixed it by forcing the "utf-8" encoding, in https://github.com/rails/activesupport-json_encoder/blob/master/lib/active_support/json/encoding/active_support_encoder.rb#L127. I forked the gem here https://github.com/mahmoud-abdelaziz/activesupport-json_encoder .
By adding gem 'activesupport-json_encoder', github: 'mahmoud-abdelaziz/activesupport-json_encoder'
, the problem is fixed.