简体   繁体   中英

Ruby on Rails Oracle encoding

I cannot seem to get the encoding right on my Oracle RoR combi. The information in the Oracle database seems to be encoded correctly. When looking up an attribute via SQL in need of special encoding I get eg 'Straße' which is what I expect. When requesting that same attribute from my RoR application I get 'Stra?e' which obviously is incorrect.

  • The NLS_LANG in ENV on the Oracle server is = AMERICAN_AMERICA.AL32UTF8
  • The encoding in the database.yml in my RoR app = utf8
  • The NLS_NCHAR_CHARACTERSET of the Oracle dbase = AL16UTF16

I tried a couple of different things by changing the parameters above but nothing worked.

Anybody have a good idea?

ENV['NLS_LANG'] ||= 'AMERICAN_AMERICA.UTF8'...\\config\\boot.rb ,它将适用于所有环境。

None of the solutions I could find on the web worked, but after reading the source of the ruby-oci8 gem, putting:

ENV['NLS_LANG'] = 'AMERICAN_AMERICA.AL32UTF8' DEFAULT_OCI8_ENCODING = 'utf-8'

in config\\boot.rb worked for me.

有用的事情是降级我的oracle增强宝石

Just run before load app

OCI8.encoding=Encoding.default_internal

You can do too on put on first line on config/boot.rb

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

This ensure that yours string will be in utf8 format when goes to database

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM