At the point your plugins are loaded, it's best to assume that nothing specific to your application is available - including ApplicationController. Consider, for example, if ApplicationController had references (includes, method invokations) which were provided by plugins that are loaded *after* this one? It's definitely going to crash and burn.
Another historical reason is that in development mode ApplicationController was unloaded and then reloaded for each request. This would mean that any additions you'd made to the class would be lost after the first time you hit your development server. ActionController::Base is a part of the framework, and so isn't reloaded since it's never expected to change. HTH James On 2/20/07, Trey Bean <[EMAIL PROTECTED]> wrote: > Indeed, this is exactly what I needed for including the module. And I > loaded the before_filter with > > ActionController::Base.send(:before_filter, :my_filter) > > One question, where exactly in the flow does the init.rb come in? I mean, > could I also do > > ApplicationController.send(:include, MyModule) to be a little more precise? > I tried and got a some errors about uninitialized constant > ApplicationController, so I'm guessing that class isn't loaded yet. > > Oh well, what works works. Is there any drawbacks to adding these to the > ActionController::Base instead of the ApplicationController? I realize that > ApplicationController inherits from ActionController::Base (and thus it > works), I am just curious. > > Trey > > > On 2/20/07, James Adam <[EMAIL PROTECTED]> wrote: > > I'm not 100% sure this is what you mean, but are you trying to include > > a module into ApplicationController? > > > > It sounds like you're creating an application controller class > > *within* your plugin, which is not what you want to do. If you really > > want to have the module included into ApplicationController > > automatically whenever the plugin is loaded, try adding something like > > this to your init.rb: > > > > ActionController::Base.send(:include, MyModule) > > > > HTH, > > > > James > > > > On 2/16/07, Trey Bean <[EMAIL PROTECTED]> wrote: > > > What's the best way to handle items in your engine's lib folder? I have > a > > > couple of support files I would normally place in my lib folder and then > > > include in my application controller. In developing my engine, I placed > > > these files in the lib folder within my engine. Then, I did what I > would > > > normally do and added the include code to the application controller in > my > > > engine. I quickly realized that this was being overwritten with the > > > surrounding application's application controller, and not wanting to > require > > > those applications to delete their application controller, I just pasted > the > > > code into the surrounding application controller (there might be a > better > > > way to do this, but one of the lines is a before_filter). > > > > > > Anyway, that works when I actually run the application, but now, when I > run > > > my tests, I get an error saying: > > > > > > `const_missing': uninitialized constant > > > ApplicationController::AuthenticatedSystem (NameError) > > > > > > So, I guess my question is, what is the best practice regarding both > files > > > in your engine's lib folder as well as including code in the surrounding > > > application's application controller? > > > > > > Thanks, > > > Trey > > > > > > _______________________________________________ > > > engine-users mailing list > > > [email protected] > > > > http://lists.rails-engines.org/listinfo.cgi/engine-users-rails-engines.org > > > > > > > > > > > > -- > > * J * > > ~ > > _______________________________________________ > > engine-users mailing list > > [email protected] > > > http://lists.rails-engines.org/listinfo.cgi/engine-users-rails-engines.org > > > > > _______________________________________________ > engine-users mailing list > [email protected] > http://lists.rails-engines.org/listinfo.cgi/engine-users-rails-engines.org > > -- * J * ~ _______________________________________________ engine-users mailing list [email protected] http://lists.rails-engines.org/listinfo.cgi/engine-users-rails-engines.org
