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

**URL:** https://meta.discourse.org/t/plugin-development-a-copy-of-applicationcontroller-has-been-removed-from-the-module-tree-but-is-still-active/98584
**Category:** Development
**Created:** [02.Октябрь.2018 22:32:06 UTC](https://meta.discourse.org/t/plugin-development-a-copy-of-applicationcontroller-has-been-removed-from-the-module-tree-but-is-still-active/98584 "2018-10-02T22:32:06Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Kampfkarren](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kampfkarren/32/109627_2.png) [@Kampfkarren](https://meta.discourse.org/u/Kampfkarren)
#### Post date: [02.Октябрь.2018 22:32:06 UTC](https://meta.discourse.org/t/plugin-development-a-copy-of-applicationcontroller-has-been-removed-from-the-module-tree-but-is-still-active/98584/1 "2018-10-02T22:32:06Z")

</div>

I get this error non-stop when developing. It used to only happen after around ~8 pages, but now it’s happening after around 1-3. The error looks like this:

 ![image](https://global.discourse-cdn.com/meta/original/3X/c/3/c3f8f7054f4adeb2bfa524818d540e2bcecb0806.png)

The blurred text is the name of the module for my plugin

Note how the name is, confusingly (and by my design), ApplicationsController. This shouldn’t be important since I’ve been having this issue long before this controller existed.

---

<div class="post-metadata">

### Author: ![gdpelican](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gdpelican/32/81308_2.png) [@gdpelican](https://meta.discourse.org/u/gdpelican)
#### Post date: [02.Октябрь.2018 22:51:01 UTC](https://meta.discourse.org/t/plugin-development-a-copy-of-applicationcontroller-has-been-removed-from-the-module-tree-but-is-still-active/98584/2 "2018-10-02T22:51:01Z")

</div>

I believe this is related to rails code reloading, and shouldn’t have to do with your naming. Something like the following happens:

- You start the app
- It loads up the core .rb files and stores the resultant classes into constants (like `ApplicationController`)
- Those classes refer to other classes, which are then loaded into constants in the same way (like `BaseController` if you have `ApplicationsController < BaseController`)
- These classes are singletons, meaning only one of them exists in the world, and are uniquely referred to by their class name. Rails keeps track of which constants you’ve defined and loads them automatically when you reference them.

Rails also automatically re-defines most of these constants when you change things. So, if you change the code for `BaseController`, rails will automatically determine that constant is stale, refresh the definition from your code, as well as any classes referencing that file (so, `ApplicationsController` will be reloaded as well to account for the new reference to `BaseController`)

This works great, _until_ you are dealing with classes which are not hot reloaded. A common example with a typical rails app is putting things into the `lib` directory (rather than the `app` directory), which are not automatically reloaded by default. So this situation arises when you have a file in `/lib` which references a file in `/app`, the `/app` file is changed, but the `/lib` file is not, leaving it pointing to a class which has been removed from the list of classes defined in the rails app.

I’ve run into this as well very occasionally with Discourse in the past, but didn’t have the gumption to troubleshoot it too hard. But, as a start, I believe you have a case where some of your plugin code is not being reloaded (maybe something needs to be added to autoload\_paths?), and is breaking when it references some constant which _is_ hot reloaded.

---

<div class="post-metadata">

### Author: ![Kampfkarren](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kampfkarren/32/109627_2.png) [@Kampfkarren](https://meta.discourse.org/u/Kampfkarren)
#### Post date: [02.Октябрь.2018 22:54:05 UTC](https://meta.discourse.org/t/plugin-development-a-copy-of-applicationcontroller-has-been-removed-from-the-module-tree-but-is-still-active/98584/3 "2018-10-02T22:54:05Z")

</div>

Thanks a lot for the response.

None of my Ruby backend code has ever restarted when I made a change, so I suspect you’re right. I also don’t think this happens when I turn cache\_classes to true. I’ll see if adding it to autoload\_paths fixes it, thanks!

---

<div class="post-metadata">

### Author: ![jamesmarkcook](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jamesmarkcook/32/168563_2.png) [@jamesmarkcook](https://meta.discourse.org/u/jamesmarkcook)
#### Post date: [15.Январь.2020 15:34:16 UTC](https://meta.discourse.org/t/plugin-development-a-copy-of-applicationcontroller-has-been-removed-from-the-module-tree-but-is-still-active/98584/4 "2020-01-15T15:34:16Z")

</div>

Вы когда-нибудь решили это?

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [16.Январь.2020 01:48:15 UTC](https://meta.discourse.org/t/plugin-development-a-copy-of-applicationcontroller-has-been-removed-from-the-module-tree-but-is-still-active/98584/5 "2020-01-16T01:48:15Z")

</div>

Теперь, когда мы перешли на Zeitwerk, этого больше не должно происходить. Если проблема сохраняется, опишите точные шаги для воспроизведения.

---

<div class="post-metadata">

### Author: ![jamesmarkcook](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jamesmarkcook/32/168563_2.png) [@jamesmarkcook](https://meta.discourse.org/u/jamesmarkcook)
#### Post date: [16.Январь.2020 09:11:43 UTC](https://meta.discourse.org/t/plugin-development-a-copy-of-applicationcontroller-has-been-removed-from-the-module-tree-but-is-still-active/98584/6 "2020-01-16T09:11:43Z")

</div>

Запуск ветки Discourse `stable` в Docker в режиме разработки с плагином. При нескольких обновлениях страницы возникает эта проблема, после чего приходится перезапускать сервер.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [17.Январь.2020 00:16:39 UTC](https://meta.discourse.org/t/plugin-development-a-copy-of-applicationcontroller-has-been-removed-from-the-module-tree-but-is-still-active/98584/7 "2020-01-17T00:16:39Z")

</div>

> [@jamesmarkcook](#):
>
> Запуск ветки Discourse `stable` в Docker в режиме разработки с собственным плагином.

Ага, ну, в следующем месяце выйдет новая стабильная версия. Текущее состояние, в котором вы находитесь, очень временное, с рабочим, хотя и неудобным обходным путём.
