Rails 4 - Acronym Controller Within a Namespace Giving 'Uninitialized Constant' Error

ruby, ruby-on-rails, ruby-on-rails-4

Solution

Looks like this is a bug that was fixed in 4.2: https://github.com/rails/rails/pull/14146

If you can't upgrade, this should work:

irb(main):001:0> ActiveSupport::Inflector.inflections(:en) { |inflect| inflect.acronym 'Admin/EDMs' }
=> /Admin\/EDMs/
irb(main):002:0> 'Admin::EDMsController'.underscore
=> "admin/edms_controller"

Problem

I'm trying to create this controller in Rails 4: ``` Admin::EDMsController ``` In my initializers/inflections.rb file, I've defined the acronym: ``` ActiveSupport::Inflector.inflections(:en) do |inflect| inflect.acronym 'EDMs' inflect.acronym 'EDM' end ``` My routes.rb file has: ``` namespace :admin do # ... some other resources ... resources :edms end ``` And my controller is defined as follows in app/controllers/admin/edms_controller.rb: ``` class Admin::EDMsController < Admin::AdminController end ``` When I try to access /admin/edms, I get the following error: ``` uninitialized constant Admin::EDMsController ``` What I've found so far: - If I rename it to Admin::EdmsController and remove the inflection definitions (i.e. everything the same except not an acronym), it works - If I move the whole thing out of the admin namespace into the root of my app (i.e. EDMsController, accessed via /edms), it works It's also worth noting that I have other controllers and resources in the admin namespace which work correctly. So it seems I can have an acronym controller, or a controller within a namespace, but not both. Any suggestions?

Original source