6

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.

robertwbradford
  • 6,181
  • 9
  • 36
  • 61
  • 1
    The plural of sheep is [sheepes](http://www.flickr.com/photos/51674157@N05/5219061771/) ^^ –  Sep 20 '11 at 17:21
  • Isn't the singular of "Communication Mean" valid? and why do you need the model name to be CommunicationMeans so badly? You can always just update the AR model file yourself and change the name and then set the database_table name in the model file – cpjolicoeur Sep 20 '11 at 17:22

2 Answers2

6

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
Mark Reed
  • 91,912
  • 16
  • 138
  • 175
  • Annoying aside: This inflector parameter must match your `rails g` parameter exactly, **including case**. If you write your migration with a snake-cased model name, the Inflector is not smart enough to match it to a camel-cased name. – Grant Birchmeier Aug 21 '19 at 22:21
0

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
roman
  • 11,143
  • 1
  • 31
  • 42