Re: Reloading controller plugins on each request

Nick
Sun, 11 Apr 2010 19:02:29 -0000

On Apr 11, 2:42 pm, Nick <n...-qGbiljoI0DQkmLvzuZlaBw@public.gmane.org>
wrote:
> Hey Frederick. Thanks for the tip. That makes sense. It turns out that
> I didn''t completely solve the problem of the plugin reloading, and
I
> think what you described is the culprit.
>
> For some reason, ActsAsDashboard::ClassMethods is not being reloaded
> for each request.
>
> I tried your suggestion of changing the plugin''s init.rb from
this:
>     require ''acts_as_dashboard''
>     ActionController::Base.send :include, ActsAsDashboard
> to this:
>     require ''acts_as_dashboard''
>     ApplicationController.send :include, ActsAsDashboard
>
> However, every request other than the first results in this error:
>     "undefined local variable or method `acts_as_dashboard''
for
> DashboardsController:Class"
> citing line 2 of app/controllers/dashboards_controller.rb :
>     1 class DashboardsController < ApplicationController
>     2   acts_as_dashboard
>
> Might you know what needs to be done to get Rails to reload
> ActsAsDashboard::ClassMethods for each request?
>
> Thanks, mate!
> Nick

Whoops, I sent that last email a bit prematurely. After switching to
using
> ApplicationController.send :include, ActsAsDashboard
in init.rb , this error:
> undefined local variable or method `acts_as_dashboard'' for
> DashboardsController:Class"
was occuring on subsequent requests because init.rb is only run when
the web server is started; it isn''t run before any web requests.

So on the first request, ActsAsDashboard has been loaded, and life''s
peachy. But on the 2nd request, all of those non-Rails framework
classes (such as ApplicationController, DashboardsController, etc) are
unloaded and then loaded. However, because my init.rb isn''t executed,
ActsAsDashboard isn''t included into ApplicationController. Thus,
#acts_as_dashboard isn''t available to DashboardsController, and the
error above occurs.

I''ve found that putting
    include ActsAsDashboard
into DashboardsController gets rid of the error above, and results in
ActsAsDashboard::ClassMethods being reloaded for each request.
However, that''s only a short-term solution.

Does anyone know what the proper fix is for this?

Thanks again,
Nick