【问题标题】:Ruby 1.9, Rails 3 and Unicode: code won't recognize Unicode charactersRuby 1.9、Rails 3 和 Unicode:代码无法识别 Unicode 字符
【发布时间】:2011-11-21 19:27:37
【问题描述】:

当我们将应用程序从 1.8.7 上的 Rails 2 迁移到 Ruby 1.9.2 上的 Rails 3 时,我正在尝试升级一些测试。测试基本确保数据库对象可以用 unicode 字符命名,以提供国际支持。

测试基本上是这样的:

#encoding: utf-8
'ä' =~ /\S/ # this passes
'ä' =~ \/w/ # this fails, apparently passed on 1.8.7
model = Model.create!(:name => '§äè®') # this causes a "Name must include at least one letter or number" validation error, which means Ruby (or Rails) is seeing the name as being blank

为了在此处发布,这一切都是基本的并且非常简化,但这些都是失败的。我还有什么需要看的吗?我知道 Ruby 不能很好地与 Unicode 配合使用,但这几乎必须保留。感谢任何帮助。

【问题讨论】:

    标签: ruby-on-rails unicode ruby-1.9


    【解决方案1】:

    看起来这是按预期工作:

    http://redmine.ruby-lang.org/issues/show/3181

    更改为 'ä' =~ /\p{L}/ 让它工作。

    【讨论】:

      猜你喜欢
      • 2010-12-29
      • 2017-07-17
      • 1970-01-01
      • 1970-01-01
      • 2013-10-17
      • 1970-01-01
      • 1970-01-01
      • 2021-03-11
      • 1970-01-01
      相关资源
      最近更新 更多