4

当我在 rails 控制台中执行以下操作时,我使用 Ruby 1.9.3 和 Rails 3.2.9:

1.9.3p125 :003 > "foot".pluralize => "foots" # 不应该是 "feet" 吗?

1.9.3p125 :004 > "tooth".pluralize => "tooths" # 不应该是 "teeth" 吗?

1.9.3p125 :009 > "goose".pluralize => "gooses" # 不应该是 "geese" 吗?

这是rails中的错误还是我做错了什么?

4

1 回答 1

10

您可以配置 rails 变形器。您的应用程序中应该有一个初始化文件来执行此操作:config/initializers/inflections.rb

然后,您可以添加一个调用来“教授”新规则:

ActiveSupport::Inflector.inflections do |inflect|
 inflect.irregular 'tooth', 'teeth'
end

重新启动服务器/控制台后,新的复数形式应该就位。

于 2012-12-31T01:14:46.320 回答