[Plugin dev.] Hook into ActionController::Base properly

Hi all,

currently I’m developing a plugin wich shoud hook into ActionController.
To do that, I’m using ActionController::Base.send(:include, …) but
when I want to call the according methods from within a controller, I
get an MethodNotError.

The following code shows what I’m currently trying. Mixing the
ViewHelpers into ActionView::Base work’s fine. The same I want to do
with ActionController:Base, but that does’n work:

#require 'widget_pool/loader'
require 'widget_pool/view_helpers'
require 'widget_pool/base'

module WidgetPool

  module Loader
    def load_widget name
      puts 'loading widget: ' + name.to_s
    end
  end

  class << self
    def enable
      puts 'starting widget_pool...'

      ActionView::Base.send :include, ViewHelpers
      ActionController::Base.send :include, Loader
    end
  end
end

WidgetPool.enable

Does anybody know, what is missing to make it work?

Thanks & Greetings

I just startet my RailsApp in a console:

ActionController::Base.instance_methods.include? ‘load_widget’

results to true

class Test < ActionController::Base
end

Test.methods.include? ‘load_widget’

results to false

How this can be?

Ok, in my example I just forgot to instantiate Test :wink:

t = Test.new
t.methods.include? ‘load_widget’

also results to true

But why I cannot call the method from withing the controller? :-/

On Jun 20, 10:35 pm, Wer S. [email protected] wrote:

Ok, in my example I just forgot to instantiate Test :wink:

t = Test.new
t.methods.include? ‘load_widget’

also results to true

But why I cannot call the method from withing the controller? :-/

How are you calling things ? My guess is you’re trying

class Test< ActionController::Base
some_method_from_your_plugin
end

For this to work some_method_from_your_plugin needs to be a class
method (since you are calling it on Test itself, not an instance of
it) but it looks like you’re only adding instance methods.

Fred

You’re right with your guess! :wink: Thanks!