2012-07-13 146 views
6

当数据库中发现的一些人物的观点一样,我得到了错误incompatible character encodings: UTF-8 and ASCII-8BIT,N,A,E等错误:不兼容的字符编码:UTF-8和ASCII-8BIT

我的环境是:

  • 滑轨:3.2.5
  • 红宝石:1.9.4p194
  • 数据库:Oracle 10g中(10.2.0.1.0)

我可以使用Toad将这些字符保存在数据库中。

我试着写这篇文章,我认为第一行:

<% # encoding: utf-8 %> 

enviroment.erb

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

但没有什么固定的这一点。

请,有人可以给些谏固定这一点。

谢谢。

+0

什么是数据库和国家字符集? 'select * from v $ nls_parameter'参数如'%CHARACTERSET'? – 2012-07-13 21:01:43

+0

正如http://stackoverflow.com/questions/1779740/incompatible-character-encodings-ascii-8bit-and-utf-8-in-ruby-1-9中的建议,你应该阅读和理解字符编码。建议的链接是一个很好的开始。 – 2012-07-16 13:31:03

+0

感谢@JustinCave为您解答,我会检查这个。 – 2012-07-22 00:49:36

回答

0

在该文件中的boot.rb我加入这一行:

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

白衣这个我解决我的问题。

5

我也有同样的问题,我与猴子补丁的搜索小时后解决它。

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 
相关问题