Updated for Rails 2.0.x. I always hate it when I run into old content about Rails on the web that doesn’t work because its outdated. Fortunately a reader, John R, pinged me and reminded me that I was being “that guy”; so I updated this post to be accurate as of Rails 2.0.x. Thanks John!

For those of you who are trying to roll on Rails, the inflector doesn’t quite work as expected with namespaces. When I create a model for media, I add the following to the Inflector settings in config/initializers/inflections.rb.

Inflector.inflections do |inflect|
  inflect.uncountable "media"
end

Then generate a scaffold for Admin::Media

C:/Projects/medias_app>ruby script/generate scaffold Admin::Media
  create  app/controllers/admin
  create  app/helpers/admin
  exists  app/views/admin/medias
  create  test/functional/admin   dependency  model
  create  app/models/
  create    test/unit/
  create    test/fixtures/
  create    app/models/medias.rb
  create    test/unit/medias_test.rb
  create    test/fixtures/medias.yml
  identical  app/views/admin/medias/_form.rhtml
  create  app/views/admin/medias/list.rhtml
  create  app/views/admin/medias/show.rhtml
  create  app/views/admin/medias/new.rhtml
  create  app/views/admin/medias/edit.rhtml
  create  app/controllers/admin/medias_controller.rb
  create  test/functional/admin/medias_controller_test.rb
  create  app/helpers/admin/medias_helper.rb
  create  app/views/layouts/medias.rhtml
  create  public/stylesheets/scaffold.css
Loaded suite script/generate
Started

Finished in 0.0 seconds.

0 tests, 0 assertions, 0 failures, 0 errors

I get a medias model in the admin folder (close but no cigar! what is “medias” anyway?).

The fix? Add the following to the inflector in config/initializers/inflections.rb as a work around:

Inflector.inflections do |inflect|
  inflect.uncountable "media", "admin::media"
end

Now generate the Admin::Media scaffold, controller, (whatever) and viola! Your generated code should function properly.

C:/Projects/media_app>ruby script/generate scaffold Admin::Media
  create  app/controllers/admin
  create  app/helpers/admin
  exists  app/views/admin/media
  create  test/functional/admin
  dependency  model
  create    app/models/
  create    test/unit/
  create    test/fixtures/
  create    app/models/media.rb
  create    test/unit/media_test.rb
  create    test/fixtures/media.yml
  identical  app/views/admin/media/_form.rhtml
  create  app/views/admin/media/list.rhtml
  create  app/views/admin/media/show.rhtml
  create  app/views/admin/media/new.rhtml
  create  app/views/admin/media/edit.rhtml
  create  app/controllers/admin/media_controller.rb
  create  test/functional/admin/media_controller_test.rb
  create  app/helpers/admin/media_helper.rb
  create  app/views/layouts/media.rhtml
  create  public/stylesheets/scaffold.css

Loaded suite script/generate
Started

Finished in 0.0 seconds.

0 tests, 0 assertions, 0 failures, 0 errors