I'm working on a project that is migrating from a rails 3.2 and ruby 1.9.x to ruby 2.2.x and rails 4.2.4 version.
When the project goes to production server, it started to throw encoding errors like this:
"\xC3" from ASCII-8BIT to UTF-8
followed by an stacktrace like:
["/var/www/suba/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.4/lib/active_support/core_ext/object/json.rb:34:in `encode'"
"/var/www/suba/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.4/lib/active_support/core_ext/object/json.rb:34:in `to_json'"
"/var/www/suba/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.4/lib/active_support/core_ext/object/json.rb:34:in `to_json_with_active_support_encoder'"
"/var/www/suba/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.4/lib/active_support/json/encoding.rb:57:in `to_json'"
"/var/www/suba/vendor/bundle/ruby/2.2.0/gems/json-1.8.3/lib/json/common.rb:223:in `generate'"
"/var/www/suba/vendor/bundle/ruby/2.2.0/gems/json-1.8.3/lib/json/common.rb:223:in `generate'"
"/var/www/suba/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.4/lib/active_support/json/encoding.rb:101:in `stringify'"
"/var/www/suba/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.4/lib/active_support/json/encoding.rb:35:in `encode'"
"/var/www/suba/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.4/lib/active_support/json/encoding.rb:22:in `encode'"
"/var/www/suba/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.4/lib/active_support/core_ext/object/json.rb:37:in `to_json_with_active_support_encoder'"
"/var/www/suba/vendor/bundle/ruby/2.2.0/gems/multi_json-1.11.2/lib/multi_json/adapters/json_common.rb:19:in `dump'"
"/var/www/suba/vendor/bundle/ruby/2.2.0/gems/multi_json-1.11.2/lib/multi_json/adapter.rb:25:in `dump'"
"/var/www/suba/vendor/bundle/ruby/2.2.0/gems/multi_json-1.11.2/lib/multi_json.rb:136:in `dump'"
"/var/www/suba/vendor/bundle/ruby/2.2.0/gems/resque-1.24.1/lib/resque/helpers.rb:25:in `encode'"
"/var/www/suba/vendor/bundle/ruby/2.2.0/gems/resque-1.24.1/lib/resque.rb:173:in `push'"
"/var/www/suba/vendor/bundle/ruby/2.2.0/gems/resque-1.24.1/lib/resque/job.rb:51:in `create'"
"/var/www/suba/vendor/bundle/ruby/2.2.0/gems/resque-1.24.1/lib/resque.rb:271:in `enqueue_to'"
"/var/www/suba/vendor/bundle/ruby/2.2.0/gems/resque-1.24.1/lib/resque.rb:252:in `enqueue'"
"/var/www/suba/app/controllers/call_center/chat_controller.rb:6:in `transcript'"
and the chat_controller.rb
line 6 on transcript
method:
def transcript
Resque.enqueue(Chat::SessionTranscript, read_request_body)
head :ok
end
def read_request_body
xml = request.body.read
Rails.logger.info("XML: #{xml}")
xml
end
In another point of our code base we solved this issue using a code like:
string.encode("UTF-8", :invalid => :replace, :undef => :replace, :replace => "?")
but the same error starts to appear in other parts.
Have anyone passed for this and how are you dealing with?
Thank you in advanced.