Rails 生成错误的复数形式 [英] Rails generate wrong pluralize form

查看:56
本文介绍了Rails 生成错误的复数形式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I use Ruby 1.9.3 and Rails 3.2.9, when I do the following in a rails console:

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

1.9.3p125 :003 > "foot".pluralize => "foots" # shouldn't it be "feet"?

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

1.9.3p125 :004 > "tooth".pluralize => "tooths" # shouldn't it be "teeth"?

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

1.9.3p125 :009 > "goose".pluralize => "gooses" # shouldn't it be "geese"?

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

is that a bug in rails pluralize or I did something wrong?

推荐答案

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

You can configure the rails inflector. There should be an initializer file in your application to do so: config/initializers/inflections.rb

然后你可以添加一个调用来teach"rails新规则:

You can then add a call to "teach" rails the new rule:

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

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

After you restart the server/console the new pluralization should be in place.

这篇关于Rails 生成错误的复数形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆