Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 547
Matchu Avatar asked Aug 07 '09 02:08

Matchu


3 Answers

This is a bug in Rails 2.3.3:

  • https://rails.lighthouseapp.com/projects/8994/tickets/2948-exception-a-copy-of-actorscontroller-has-been-removed-from-the-module-tree-but-is-still-active

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

  • http://github.com/rails/rails/commit/d37ac7958fc88fdbf37a8948102f6b4e45c530b3

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.

like image 196
mixonic Avatar answered Nov 11 '22 13:11

mixonic


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.

like image 37
Boris Avatar answered Nov 11 '22 14:11

Boris


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.

like image 22
airy Avatar answered Nov 11 '22 13:11

airy