An Error Caused By Not Missing a Constant

by Brian on 12/22/2008

Usually, when programming you get an error that you are missing a variable, or something, but in Rails, sometimes you get errors like this:

ArgumentError (Object is not missing constant WhateverController!)

There’s been a few other occasions where I have gotten errors that made absolutely no sense. I think they are caused by the “magic” that Rails does in the background to make a lot if its conventions work.

I Googled this error and learned that it is sometimes caused by calling the initializer of a class that does not have one, such as calling .new on a notifier. However, that was not the cause of my error. I had a namespace defined in my routes.rb file, however, the controllers in that namespace were not in the proper directories, they were just in the root app/controllers, directory, rather than app/controllers/namespace/whatever_controller.rb. I think in most cases Rails is smart enough to figure out that your controller is in app/controllers, but I just happened to be deploying my app inside of mod_rails (phusion).

Phusion must be playing around with the magic.

Related posts:

  1. NoMachine Mac OS X 10.6.3 bug
  2. The problem with dynamically typed languages
  3. Filter Sensitive Data From Your Logs
  4. Liberal Leadership and Twitter
  5. Generating Schema from Existing Database
  • Daniel Mircea

    I know this is an old post, but thank you. It saved me quite some time.

  • Spencer

    Thanks, was having this exact error with Rails 2.3.11 after playing with my routes. Didn’t show up until I deployed inside phusion.

  • http://twitter.com/ajfaraday Andrew Faraday

    I had this error recently. It seems to have been caused by me defining a method (in one of my models) as Self.method_name as opposed to self.method_name

Previous post:

Next post: