Re: Reloading controller plugins on each request

Frederick Cheung
Sun, 11 Apr 2010 22:26:35 -0000

On Apr 11, 7:42 pm, Nick <n...-qGbiljoI0DQkmLvzuZlaBw@public.gmane.org>
wrote:
>
> 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?

If you want something to be reloadable you should use
require_dependency to load it. The main thing though is that a
plugin''s init.rb is not re-run between requests, so the include you do
on ApplicationController is lost after the first request.

Fred
>
> Thanks, mate!
> Nick
>
> On Apr 10, 2:32 pm, Frederick Cheung
<frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> wrote:
>
>
>
> > On Apr 10, 4:38 pm, Nick
<n...-qGbiljoI0DQkmLvzuZlaBw@public.gmane.org> wrote:
>
> > > On Apr 10, 11:06 am,
"kel...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org"
<kel...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>
> > > > Did you try require_dependency instead of require?
>
> > > I''ve never heard of require_dependency. I just gave it a
try, but
> > > unfortunately, all requests but the first result in this error:
>
> > > "A copy of ActsAsDashboard::ClassMethods has been removed
from the
> > > module tree but is still active!"
>
> > > That behaviour also occurs when I put this in environment.rb:
>
> > > ActiveSupport::Dependencies.explicitly_unloadable_constants
<<
> > > ''ActsAsDashboard''
>
> > Just for your enlightenment, a big part of the problem is that you
> > were including your module in ActionController::Base. This was
> > problematic because the rails framework (including
> > ActionController::Base) doesn''t get reloaded, but you were
forcing
> > Rails to reload your module event though ActionController::Base was
> > still hanging onto it (you wouldn''t have had this issue if
you''d
> > included it in ApplicationController. Using require rather than
> > require_dependency sidesteps Rails'' dependency stuff (which
is the
> > thing that manages code reloading)
>
> > Fred