0

I'm using Rails 3.2.1 and I have stuck on some problem for quite long.

I'm using oracle enhanced adapter and I have raw(16) (uuid) column and when I'm trying to display the data there is 2 situations:

1) I see the weird symbols

2) I'm getting incompatible character encoding: Ascii-8bit and utf-8.

In my application.rb file I added the config.encoding = 'utf-8' and in my view file I added '#encoding=utf-8' But so far nothing worked

I also tried to add html_safe but it failed .

How can I safely diaply my uuid data?

Thank you very much

Answer: I used the unpack method to convert the binary with those parameters H8H4H4H4H12 and in the end joined the array :-)

4

1 回答 1

0

RAW数据类型是可以采用任何值的字节字符串。这包括在 ASCII 或 UTF-8 或任何字符集中无法转换为任何有意义的二进制数据。

在继续之前,您真的应该阅读Joel Spolsky 关于字符集和 unicode 的说明。

现在,由于数据不能可靠地转换为字符串,我们如何显示它?通常我们对其进行转换或编码,例如:

  • 我们可以使用十六进制表示,其中每个字节都转换为两个[0-9A-F]字符(在 Oracle 中使用该RAWTOHEX函数)。这适用于显示小的二进制字段,例如RAW(16).
  • 您还可以在包中使用 Oracle 中的其他编码,例如base 64 。UTL_ENCODE
于 2013-07-02T15:20:11.357 回答