Error: Incompatible character encodings: UTF-8 and ASCII-8BIT

I received an incompatible character encodings: UTF-8 and ASCII-8BIT when some characters were found in the database: ñ, á, é, etc.

My surrounding:

  • Rails: 3.2.5
  • Ruby: 1.9.4p194
  • Database: Oracle 10g (10.2.0.1.0)

I can save these characters in a database using Toad.

I tried to write this in the first line of my view:

 <% # encoding: utf-8 %> 

In enviroment.erb

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

But nothing was fixed.

Please can someone advise me to fix this.

Thank.

+6
oracle ruby-on-rails utf-8
Jul 13 '12 at 21:00
source share
2 answers

In the boot.rb file, I added this line:

ENV ['NLS_LANG'] = 'AMERICAN_AMERICA.UTF8'

In this I solved my problem.

0
Jun 27 '13 at 20:27
source share

I have the same problems and I solved it after several hours of searching with a monkey patch.

  module ActiveSupport #:nodoc: class SafeBuffer < String def safe_concat(value) value = force_utf8_encoding(value) raise SafeConcatError unless html_safe? original_concat(value) end def concat(value) value = force_utf8_encoding(value) if !html_safe? || value.html_safe? super(value) else super(ERB::Util.h(value)) end end alias << concat private def force_utf8_encoding(value) self.force_encoding('UTF-8').html_safe unless self.encoding.name == 'UTF-8' value = (value).force_encoding('UTF-8').html_safe unless value.nil? || value.encoding.name == 'UTF-8' value end end end 
+5
May 24 '13 at 14:39
source share



All Articles