The approach I've used is to place the relevant code in the my_engine.rb module under lib, then include MyEngine in application.rb
That approach has worked fairly well for me. - Tony On 2/21/07, Trey Bean <[EMAIL PROTECTED]> wrote:
That makes sense. It just feels a little weird sending something to ActionController::Base (I'd rather programatically add these lines to the surrounding app's application controller), but I think I can get over it. One further question though: I mentioned in my last email, that I did the same thing with a before_filter and put the following in my init.rb ActionController::Base.send(:before_filter, :my_filter) This works when I run the site with script/server, but if I run my tests with rake test:plugins PLUGIN=my_plugin, it doesn't invoke the before_filter. I've placed a puts line at the top of the my_filter method, so I can see when it's called, and through scirpt/server it is called with every request, as expected, but through the tests, it never gets called. The odd thing is that I've verified that init.rb is getting called and that my other line in init.rb, ActionController::Base.send(:include, MyModule) is being loaded. Should I not be doing this with before filters? Or should I be doing something else in the test to make sure the before_filter is set up correctly. Trey On 2/21/07, James Adam <[EMAIL PROTECTED]> wrote: > > 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 > _______________________________________________ engine-users mailing list [email protected] http://lists.rails-engines.org/listinfo.cgi/engine-users-rails-engines.org
-- Tony Arcieri ClickCaster, Inc. [EMAIL PROTECTED] (970) 232-4208
_______________________________________________ engine-users mailing list [email protected] http://lists.rails-engines.org/listinfo.cgi/engine-users-rails-engines.org
