# Application.rb overload?

**URL:** <https://www.ruby-forum.com/t/application-rb-overload/107542>\
**Category:** Engines\
**Created:** [June 22, 2007, 8:30pm UTC](https://www.ruby-forum.com/t/application-rb-overload/107542 "2007-06-22T20:30:47Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![pgundlach](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b9e5f3/32.png) [@pgundlach](https://www.ruby-forum.com/u/pgundlach)\
**Post date:** [June 22, 2007, 8:30pm UTC](https://www.ruby-forum.com/t/application-rb-overload/107542/1 "2007-06-22T20:30:47Z")

</div>

Hi,

I have an authentification application with methods such as “logged\_in?”  
in controllers/application.rb. But when I moved the application.rb from  
a real app to an engine, these methods are not known anymore. I call the  
method from a controller within the engine. Did I miss anything?

Side note: the login\_controller in the engine is called, so the engine  
is active in a way.

Patrick

---

<div class="post-metadata">

**Author:** ![pgundlach](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b9e5f3/32.png) [@pgundlach](https://www.ruby-forum.com/u/pgundlach)\
**Post date:** [June 24, 2007, 12:28pm UTC](https://www.ruby-forum.com/t/application-rb-overload/107542/2 "2007-06-24T12:28:09Z")

</div>

Repost, because I wasn’t subscribed to the mailing list:

> I have an authentification application with methods such as “logged\_in?”  
> in controllers/application.rb. But when I moved the application.rb from  
> a real app to an engine, these methods are not known anymore. I call the  
> method from a controller within the engine. Did I miss anything?
> 
> Side note: the login\_controller in the engine is called, so the engine  
> is active in a way.
> 
> Patrick

---

<div class="post-metadata">

**Author:** ![pgundlach](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b9e5f3/32.png) [@pgundlach](https://www.ruby-forum.com/u/pgundlach)\
**Post date:** [June 24, 2007, 4:36pm UTC](https://www.ruby-forum.com/t/application-rb-overload/107542/3 "2007-06-24T16:36:12Z")

</div>

IIRC, engines cause rails to scan  
plugin/app/controller/\*\*/\*\_controller.rb.

If you are overriding ApplicationController in the plugin, you might  
need to go to plugin/lib or somewhere else guaranteed to load.

Just a Guess,  
Marc

---

<div class="post-metadata">

**Author:** ![pgundlach](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b9e5f3/32.png) [@pgundlach](https://www.ruby-forum.com/u/pgundlach)\
**Post date:** [June 24, 2007, 6:43pm UTC](https://www.ruby-forum.com/t/application-rb-overload/107542/4 "2007-06-24T18:43:44Z")

</div>

Hi Marc,

> IIRC, engines cause rails to scan  
> plugin/app/controller/\*\*/\*\_controller.rb.

Most likely, yes.

> If you are overriding ApplicationController in the plugin, you might  
> need to go to plugin/lib or somewhere else guaranteed to load.

What I do now is copy the code to myplugin.rb and require it from  
init.rb. This works fine, although it doesn’t feel ‘right’. But what  
counts is that it works as intended so thanks for the hint!

Patrick

---

<div class="post-metadata">

**Author:** ![pgundlach](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b9e5f3/32.png) [@pgundlach](https://www.ruby-forum.com/u/pgundlach)\
**Post date:** [June 26, 2007, 7:09pm UTC](https://www.ruby-forum.com/t/application-rb-overload/107542/5 "2007-06-26T19:09:04Z")

</div>

The approach I’ve used was to name a library after your engine (e.g.  
module  
FooEngine in foo\_engine.rb in the plugin’s lib directory) then include  
it  
into your application.rb

–  
Tony A.  
ClickCaster, Inc.

---

<div class="post-metadata">

**Author:** ![pgundlach](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b9e5f3/32.png) [@pgundlach](https://www.ruby-forum.com/u/pgundlach)\
**Post date:** [June 26, 2007, 6:01pm UTC](https://www.ruby-forum.com/t/application-rb-overload/107542/6 "2007-06-26T18:01:54Z")

</div>

It seems wrong to me that you’d even want a file called  
“application.rb” in a plugin. If you want methods to be available to  
all controllers, you can achieve this by adding the methods to  
ActionController::Base via module inclusion.

Having routable controllers in plugins doesn’t mean that _everything_  
under your\_plugin/app should get mixed - code mixing is the special  
case, and shouldn’t be relied upon too much.
