ApplicationController 的副本已从模块树中删除,但仍处于活动状态

发布于 2024-08-01 14:49:39 字数 826 浏览 11 评论 0原文

每当两个并发 HTTP 请求发送到我的 Rails 应用程序时,第二个请求总是返回以下错误:

ApplicationController 的副本已从模块树中删除,但仍然处于活动状态!

从那里它给出了一个无用的堆栈跟踪,其效果是“我们完成了标准服务器的内容,在 ApplicationController 上运行了第一个 before_filter (我检查过;它只是先运行哪个过滤器)”,然后提供下列:

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

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

我假设

是一个通用的响应,并没有真正说明太多。 Google 似乎告诉我开发 Rails Engines 的人会遇到这种情况,但我没有这样做。 我所做的只是将我的 Rails 应用程序从 2.2(2.1?)升级到 2.3。

导致此错误的可能原因有哪些?我该如何追踪到底发生了什么? 我知道这个问题很模糊,那么还有其他信息有帮助吗?

更重要的是:我刚才尝试在“生产”环境中进行测试运行,并且错误似乎并未持续存在。 那么,这只是影响发育吗,我不用太担心吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

青巷忧颜 2024-08-08 14:49:39

这是 Rails 2.3.3 中的一个错误:

在 2-3-stable 中有一个补丁(但不完整?):

你有解决该问题的几个选项:

  • 恢复到 Rails 2.3.2,等待 2.3.4 发布,可能在 8 月底。 2.3.3 有一些不好的问题,所以这可能是最好的。
  • 该问题不应发生在生产模式下,也不会发生在 Thin 服务器。 如果您在生产模式下的 Google Engine 上遇到此问题,则该补丁是您唯一的希望。 如果仅在开发模式下,您可以使用 Thin 而不是 Mongrel 来运行本地服务器。
  • 如果是 Google Engine,您可以退出 Google Engine,并以其他方式托管您的应用。 但这看起来工作量很大。

祝你好运,这是很多人都遇到的一个非常糟糕的错误。

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.

回忆那么伤 2024-08-08 14:49:39

除了其他答案中提到的解决方法之外,我还遇到了另外两个:

  1. 将“config.cache_classes = false”添加到您的 config/environments/development.rb 文件中。 这有一个不幸的副作用,即每当您想查看更改时都需要重新启动服务器。
  2. 在引擎的控制器类中添加“unloadable”。 请参阅 http://strd6.com/?p=250http://dev.rubyonrails.org/ticket/6001

我没有尝试过第二种方法,因为我发现了另一种方法首先是解决方案,但当然需要权衡避免编辑插件代码(如果下载了较新版本的插件,则可能会恢复插件代码),以及无需重新启动开发服务器而提供的开发便利性之间存在权衡第二个解决方案中的时间。

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.

小情绪 2024-08-08 14:49:39

我在 Rails 2.3.4 上的新引擎遇到了同样的问题,我找到了解决方案 此处

调用 unloadable 方法解决了我的问题。

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.

蓝色星空 2024-08-08 14:49:39

诡异的。

尝试运行“rakerails:update”以确保配置脚本是最新的。 您可能必须根据模板应用程序检查现有的。

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.

路弥 2024-08-08 14:49:39

我遇到了这个错误,根据记忆,这是修复它的三件事之一。

1)我需要更新 mongrel/rack
2)我有一个来自restful身份验证的环境变量,我已将其从environment.rb移至生产.rb和development.rb文件中 - 将其移回environment.rb似乎有帮助
3) will_paginate 已经过时了

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

迷雾森÷林ヴ 2024-08-08 14:49:39

我们在命名空间模块中调用了 activerecord 模型,该模型覆盖了“name”类方法。 Rails 期望 name 方法返回 Product::Categories::MilkProducts::Firstproduct 但只获取 Firstproduct 并抛出错误。 因此,如果您收到此错误,请首先检查您是否重新定义了 self.name。

  • Firstproduct.method(:name).owner 应该是模块
  • Firstproduct.method(:name).source_location

源:

module Product::Categories::MilkProducts
  class Base
    def self.name
      self.to_s.demodulize
    end
  end
  class Firstproduct < Base
    self.product = Product.first
  end
end

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文