Rails: Handling a scaffolding, such as “Sheep,” th

2020-07-11 05:38发布

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.

2条回答
疯言疯语
2楼-- · 2020-07-11 06:02

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
查看更多
贪生不怕死
3楼-- · 2020-07-11 06:04

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
查看更多
登录 后发表回答