Rails 2.3.2 Object not Missing Constant Xxx

rails ruby debugging namespace routes

08|19|2009

I ran into this error earlier, and I got to tell you, this is really one puzzling error message.

Basically I have the code in my routes that does this:

    map.resource :account, 
      :name_prefix => 'doctor_', 
      :path_prefix => 'doctor',
      :requirements => { :namespace => 'doctor' }

This basically frees me from creating almost identical controllers for each user type, instead I just have to create views for app/views/doctor/accounts, app/views/patient/accounts, etc.

This code has been working perfectly for 2-3 weeks, and recently, my colleague ran into the dreaded "Object not missing constant AccountsController!". After much hair pulling and debugging, I've narrowed it down to the routeSet object for that route entry described above, which expects a controller doctor/accounts instead of just accounts. I tried specifying a controller (just accounts), but it failed to override the setting.

Finally, I tried changing my requirement name to :namespacing instead. What do you know? It worked! I guess the routing system uses the requirement namespace in a special manner, but the weird thing is this only kicked in during the integration tests, so maybe it's special within that context only.

blog comments powered by Disqus