Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 522
Rutger Avatar asked Dec 16 '22 04:12

Rutger


2 Answers

Add ENV['NLS_LANG'] ||= 'AMERICAN_AMERICA.UTF8' to ...\config\boot.rb and it will work on all environments.

like image 179
Jiemurat Avatar answered Dec 30 '22 03:12

Jiemurat


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.

like image 38
Tim P Avatar answered Dec 30 '22 02:12

Tim P