A bit of metal middleware I use decided to break on me when I upgraded haywood.edu to Rails 2.3.3. The code starts like this:
1 2 3 4 5 | class Notifications def self.call(env) if env["PATH_INFO"] =~ /^\/notifications/ notices = Notice.all ... |
That
1 | notices = Notice.all |
turned out to be the culprit. The error:
1 2 3 4 5 6 7 8 | /!\ FAILSAFE /!\ Mon Jul 27 17:49:54 -0400 2009 Status: 500 Internal Server Error A copy of Notifications has been removed from the module tree but is still active! #{ruby_path}/lib/ruby/gems/1.8/gems/activesupport-2.3.3/lib/active_support/dependencies.rb:414:in `load_missing_constant' #{ruby_path}/lib/ruby/gems/1.8/gems/activesupport-2.3.3/lib/active_support/dependencies.rb:96:in `const_missing' #{app_path}/app/metal/notifications.rb:7:in `call' #{ruby_path}/lib/ruby/gems/1.8/gems/rails-2.3.3/lib/rails/rack/metal.rb:44:in `call' ... |
A quick Google search yielded blog posts and articles covering related problems with plug-ins, engines and gems. One result suggested making the troublesome class “unloadable”, and the suggestions in the post’s comments followed that same line of thinking. None of these suggestions fixed my problem. There was no specific mention of this happening in middleware except for the lighthouse ticket that lead me to the fix. After reading a comment by Flip Sasser, I changed the problem code to
1 | notices = ::Notice.all |
to be sure that Notifications looking for Notice in the right context.
To be honest, I am new to middleware. I consider this a step in learning how it fits in with the larger Rails picture. If you have input on how the above problem occurred in the first place, please comment.