0

I am trying to generate a model and resources using

rails g model AreaOfLaw name

This creates area_of_laws as the plural version, but I want areas_of_law. As suggested in How do I override rails naming conventions? I have added the following to /config/initializers/inflections.rb:

ActiveSupport::Inflector.inflections do |inflect|
  inflect.irregular 'area of law', 'areas of law'
end

This custom inflection doesn't work when running a generator even though it does work in rails console:

"area of law".pluralize
=> "areas of law"

How can I make this work for generators?

Community
  • 1
  • 1
matharden
  • 757
  • 6
  • 15
  • What do you mean by making this "work for generators"? – MrYoshiji Mar 11 '13 at 17:47
  • @MrYoshiji like the first line above `rails g model AreaOfLaw` – matharden Mar 11 '13 at 17:52
  • See if this helps http://stackoverflow.com/questions/11835428/using-rails-inflections-with-rails-generate – Speed Mar 11 '13 at 18:33
  • Thanks @Speed, I added `inflect.uncountable %w(AreaOfLaw area_of_law)` that cuts the 's' from the end given me `area_of_law`, but I'm hoping to get `areas_of_law`. – matharden Mar 11 '13 at 18:44
  • and `inflect.irregular`does not work? Hmm, curious. Maybe try opening an issue on the Rails repository? – Speed Mar 11 '13 at 18:51

1 Answers1

4

If you do

inflect.irregular 'area_of_law', 'areas_of_law'

then it works:

'AreaOfLaw'.tableize
# => "areas_of_law"

Might be nicer to have the model named LawArea instead though.

AJcodez
  • 31,780
  • 20
  • 84
  • 118