小编Jas*_*son的帖子

Ruby/ActiveRecord在从字段中删除空格后没有检测到更改

我试图使用mysql2适配器和ActiveRecord从MySQL数据库中的各个字段中删除空格和回车:
Ruby 1.9.3p194
ActiveRecord 3.2.8
MySQL 5.5.28

foo = People.find(1)
foo.name => "\rJohn Jones"
foo.name.lstrip! => "John Jones"
foo.name => "John Jones"
foo.changes => {} #no changes detected to foo.name???
foo.save => true # but does nothing to database.
Run Code Online (Sandbox Code Playgroud)

如果我做:

foo.name = "John Jones"
foo.save => true
People.find(1).name => "John Jones" # this works and saves to database
Run Code Online (Sandbox Code Playgroud)

我已经搜遍了这个......有什么建议吗?

ruby mysql activerecord

7
推荐指数
1
解决办法
194
查看次数

标签 统计

activerecord ×1

mysql ×1

ruby ×1