如何覆盖Rails的命名约定? [英] How do I override rails naming conventions?
问题描述
我有一个名为"clothing"的模型,我想成为单数(一件衣服).默认情况下,rails说复数是服装.对或错,我认为如果复数为衣服",则可读性更高.
I have a model named "clothing" which I want to be the singlular (one piece of clothing). By default, rails says the plural is clothings. Right or wrong, I think it will be more readable if the plural is "clothes".
如何覆盖复数命名约定?我可以在模型中正确执行此操作,因此不必一遍又一遍地进行吗?这将如何改变路由的处理方式(我使用的是宁静的体系结构)?
How do I override the plural naming convention? Can I do it right in the model so I don't have to do it over and over? How will this change how routes are handled (I am using restful architecture)?
推荐答案
我不是RoR专家,但确实找到了可能的方法.从引用的站点,您可以在config/initializers/inflections.rb
文件内添加拐点规则:
I'm no RoR expert, but did find a possible approach. From the referenced site you can add inflection rule inside the config/initializers/inflections.rb
file:
# Add new inflection rules using the following format
ActiveSupport::Inflector.inflections do |inflect|
inflect.irregular 'clothing', 'clothes'
end
这篇关于如何覆盖Rails的命名约定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!