Rails YAML无法从mysql检索回车

时间:2014-12-05 11:08:49

标签: mysql ruby-on-rails ruby yaml

假设我的模型SomeResource具有属性data

a = SomeResource.find 1
a.data = "abc"
a.save

在mysql中

select length(data) from some_resources where id = 1;
+--------------+
| length(data) |
+--------------+
|            8 |
+--------------+

现在,

a.data = "abc\r"
#=> #<SomeResource id: XX,.., data: "abc\r",..>
a.save

检查它是否存储在mysql中

select length(data) from some_resources where id = 1;
+--------------+
| length(data) |
+--------------+
|            9 |
+--------------+

显然长度增加,表明新字符存储在数据库中。

尝试在rails控制台中检索它:

a = SomeResource.find 1
a.data
#=> "abc"

\r迷路了。

为什么回车丢失了?

MySql详细信息:

+-------------------------+-------------------------+
| Variable_name           | Value                   |
+-------------------------+-------------------------+
| innodb_version          | 5.5.38                  |
| protocol_version        | 10                      |
| slave_type_conversions  |                         |
| version                 | 5.5.38-0ubuntu0.14.04.1 |
| version_comment         | (Ubuntu)                |
| version_compile_machine | x86_64                  |
| version_compile_os      | debian-linux-gnu        |
+-------------------------+-------------------------+

Rails版本: Rails 3.2.13

Ruby版本:ruby 1.8.7 (2012-06-29 patchlevel 370) [x86_64-linux]

0 个答案:

没有答案