I''ve been looking at bottling some functionality up into a plugin, but
I''m
having some problems including it.
The structure I have is:
/app/controllers/admin/base_controller.rb:
class Admin::BaseController > ApplicationController
#snip#
end
/vendor/plugins/myplugin/lib/my_module.rb:
module MyModule
def new_func
"New Function"
end
end
/vendor/plugins/myplugin/init.rb:
require ''my_module''
Admin::BaseController.send :include, MyModule
However, this gives me an ''uninitialized constant ApplicationController
(NameError)'' error when I start Rails
Can I do what I''m trying to do this way? And if not, what are my
alternatives?
Thanks,
Gareth
> /vendor/plugins/myplugin/init.rb: > require ''my_module'' > Admin::BaseController.send :include, MyModule > > > However, this gives me an ''uninitialized constant ApplicationController > (NameError)'' error when I start Rails > > Can I do what I''m trying to do this way? And if not, what are my alternatives? > > Thanks, > GarethTry require ''application''. Though, this will probably be problematic in dev mode. If you''re on edge rails, try the new Dispatcher.to_prepare stuff: Dispatcher.to_prepare :my_plugin do require ''my_module'' require ''application'' Admin::BaseController.send :include, MyModule end http://dev.rubyonrails.org/browser/trunk/railties/lib/dispatcher.rb#L63 -- Rick Olson http://techno-weenie.net
> Dispatcher.to_prepare :my_plugin do > require ''my_module'' > require ''application'' > Admin::BaseController.send :include, MyModule > end > > http://dev.rubyonrails.org/browser/trunk/railties/lib/dispatcher.rb#L63require ''my_module'' Dispatcher.to_prepare :my_plugin do require_dependency ''application'' # allows dev reloading Admin::BaseController.send :include, MyModule end -- Rick Olson http://techno-weenie.net