Rails: Handling a scaffolding, such as “Sheep,” that has the same plural and singular form

我们两清 提交于 2019-12-21 12:33:50

问题


I'm wanting to create a model called CommunicationMeans (or, alternatively, MeansOfCommunication). However, this is both the singular and plural form of this term. I ran this:

$ rails g scaffold CommunicationMeans

It generated a model named CommunicationMean and a controller named CommunicationMeansController. I need the model to also be named CommunicationMeans. I vaguely remember an example in some documentation using a Sheep model, but what is the "correct" way to handle this situation? Thanks.


回答1:


In config/initializers/inflections.rb, you can add 'means' as uncountable.

EDIT: Ok, had to add the whole compound, in camel case, but it worked:

ActiveSupport::Inflector.inflections do |inflect|
   inflect.uncountable 'CommunicationMeans'
end



回答2:


I think adding it to the inflection rules in config/initializers/inflections.rb should be sufficient - i.e.

Inflector.inflections do |inflect|
    inflect.plural 'sheep', 'sheep'
end


来源:https://stackoverflow.com/questions/7489054/rails-handling-a-scaffolding-such-as-sheep-that-has-the-same-plural-and-sin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!