ruby-on-railsrubyscaffoldinflector

Rails 3 Inflection Problem


I'm having a problem with generating scaffold for a Regatta. When I run

rails g scaffold Regatta name:string start_date:datetime

I get a model named regattum and a controller called regatta_controller (instead of regattas_controller)

  invoke  active_record
  create    db/migrate/20110609221608_create_regatta.rb
  create    app/models/regattum.rb
  invoke    test_unit
  create      test/unit/regattum_test.rb
  create      test/fixtures/regatta.yml
   route  resources :regatta
  invoke  scaffold_controller
  create    app/controllers/regatta_controller.rb
  invoke    erb
  create      app/views/regatta
  create      app/views/regatta/index.html.erb
  create      app/views/regatta/edit.html.erb
  create      app/views/regatta/show.html.erb
  create      app/views/regatta/new.html.erb
  create      app/views/regatta/_form.html.erb
  invoke    test_unit
  create      test/functional/regatta_controller_test.rb
  invoke    helper
  create      app/helpers/regatta_helper.rb
  invoke      test_unit
  create        test/unit/helpers/regatta_helper_test.rb
  invoke  stylesheets

identical public/stylesheets/scaffold.css

Obviously this is an inflection problem, but whenever I modify /config/initializers/inflections.rb I get an error saying:

The name 'Regatta' is either already used in your application or reserved by Ruby on Rails. Please choose an alternative and run this generator again.

I have tried everything I can think of to make it work, but I keep getting an error. Any advice on a solution or a workaround would be greatly appreciated!


Update

Here are some of the things I have tried:

ActiveSupport::Inflector.inflections do |inflect|
  inflect.irregular 'regatta', 'regattas'
end

That didn't change anything so I tried a few of the options below, among others,in varying combinations to no avail:

 inflect.plural 'regatta', 'regattas'
  inflect.singular 'regattas', 'regatta'
  inflect.singular 'regatta', 'regatta'

Update 2

Here is the code I used in inflections.rb once I figured out what I was doing wrong:

ActiveSupport::Inflector.inflections do |inflect|
  inflect.plural 'regatta', 'regattas'
  inflect.singular 'regatta', 'regatta'
  inflect.singular 'regattas', 'regatta'
end

Hopefully this will help someone out in the future!


Solution

  • Given the error message saying that Regatta is already in use in your application (it's obviously not reserved by Rails), I'm guessing the Regattum model is still in place.

    I'd recommend destroying the scaffold and trying again. It sounds like, once a word is already defined in the application, Rails has a built-in protection against changing the inflection. So, this error being thrown is to protect against unexpected behavior in this very situation.