Question

Whenever two concurrent HTTP requests go to my Rails app, the second always returns the following error:

A copy of ApplicationController has been removed from the module tree but is still active!

From there it gives an unhelpful stack trace to the effect of "we went through the standard server stuff, ran your first before_filter on ApplicationController (and I checked; it's just whichever filter runs first)", then offers the following:

/home/matchu/rails/torch/vendor/rails/activesupport/lib/active_support/dependencies.rb:414:in `load_missing_constant'

/home/matchu/rails/torch/vendor/rails/activesupport/lib/active_support/dependencies.rb:96:in `const_missing'

which I'm assuming is a generic response and doesn't really say much.

Google seems to tell me that people developing Rails Engines will encounter this, but I don't do that. All I've done is upgrade my Rails app from 2.2 (2.1?) to 2.3.

What are some possible causes for this error, and how can I go about tracking down what's really going on? I know this question is vague, so would any other information be helpful?

More importantly: I tried doing a test run in a "production" environment just now, and the error doesn't seem to persist. Does this only affect development, then, and need I not worry too much?

Was it helpful?

Solution

This is a bug in Rails 2.3.3:

There is a patch for it (but incomplete?) in 2-3-stable:

You have a few options to address the problem:

  • Revert to Rails 2.3.2, wait for 2.3.4 to come out, probably at the end of August. 2.3.3 has a couple bad issues, so that might be best.
  • The problem should not happen in production mode, nor will it happen in development mode under the Thin server. If you are having this issue on Google Engines in production mode, the patch is your only hope. If it's only in dev mode, you can just run your local server with Thin instead of Mongrel.
  • If it is Google Engines, you can move off of Google Engines and host your app another way. This seems like a lot of work though.

Best of luck, this is a really bad bug many people are running into.

OTHER TIPS

I addition to the workarounds mentioned in the other answers, I have encountered two others:

  1. Add "config.cache_classes = false" to your config/environments/development.rb file. This has the unfortunate side effect of requiring you to restart your server whenever you want to see your changes.
  2. Add 'unloadable' inside your controller classes in your engine. See http://strd6.com/?p=250 and http://dev.rubyonrails.org/ticket/6001

I haven't tried the second approach, since I found the other solution first, but there is of course a trade-off between avoiding having to edit plugin code, which may be reverted if a newer version of the plugin is downloaded, and then the ease of development provided by not having to restart the development server all the time in the second solution.

i faced with same problem for my new engine on rails 2.3.4 and i found solution here.

calling unloadable method solved my problem.

Weird.

Trying running "rake rails:update" to make sure the configs are scripts are up to date. You may have to check the existing ones against a template application.

i had this error and from memory it was one of one of these three things that fixed it.

1) I needed to update mongrel/rack 2) I had an environment variable from restful authentication that i had moved into the production.rb and development.rb files from the environment.rb - shifting it back to environment.rb seemed to help 3) will_paginate was out of date

We called out to an activerecord model in a namespaced module which overrides the "name" class method. Rails expects that the name method returns Product::Categories::MilkProducts::Firstproduct but gets just Firstproduct and throws an error. So if you get this error first check if you redefined self.name.

  • Firstproduct.method(:name).owner should be Module
  • Firstproduct.method(:name).source_location

source:

module Product::Categories::MilkProducts
  class Base
    def self.name
      self.to_s.demodulize
    end
  end
  class Firstproduct < Base
    self.product = Product.first
  end
end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top