Magic to pass reference to a controller

I’m implementing a helper library which provide both view helpers and
controller helpers. To save the end user from having to specifically
pass in a reference to self on every call I was wondering if there was a
way for a class to get access to the calling controller object
automagically.

One suggestion was Thread.current[:controller] … but that sounds a bit
nasty

e.g.

class MyTestController < ActionController:Base
def test
@ref = MyModule::MyClass.new({:a_load_of_settings => ‘go here’})
end
end

module MyModule
class MyClass
def initialize(settings ={})
#I need a reference to the controller
end
end
end

Wouldn’t it be more natural to write the helper methods in modules
that you’d mix into the controller using extend and include?

On Apr 28, 6:26 am, Alex M. [email protected]