I've created a simple plugin to extend the functionality of my
controllers. So in my plugins/<plugin>/lib directory I created the
following module:
module MyPlugin
def self.included(base)
include InstanceMethods
end
module InstanceMethods
def some_method
..
end
end
end
To extend the controllers just put
include MyPlugin
somewhere in ApplicationController and that's it... I thought!
I found out that 'include InstanceMethods' will only work if my
application is running in 'development'. When running in 'production'
calling 'some_method' will result in a ActionController::UnknownAction
exception.
If I change the 'include' line into:
base.send(:include, InstanceMethods)
things will work fine, so after all there's no problem at all, but I'm
just curious of someone of has the same experience and if there's a
difference between 'include' and 'base.send :include'?
somewhere in ApplicationController and that's it... I thought!
I found out that 'include InstanceMethods' will only work if my
application is running in 'development'. When running in 'production'
calling 'some_method' will result in a ActionController::UnknownAction
exception.
If I change the 'include' line into:
base.send(:include, InstanceMethods)
things will work fine, so after all there's no problem at all, but I'm
just curious of someone of has the same experience and if there's a
difference between 'include' and 'base.send :include'?
Well it's all about who's doing the include, in one case you're doing
it to MyPlugin (after the module has been included in
ApplicationController), in the other case you're doing it to
ApplicationController itself (since that's what Base will be). I
suspect you're just been lucky: in development mode you keep getting
reloaded, so the first time round the methods aren't added to
ApplicationController, but they are added to MyPlugin, and the second
and following times since they are in MyPlugin they are also added to
ApplicationController. When class caching is on (ie in production)
things are only loaded once and so the methods aren't added to the
controllers. (not sure if you're doing this on purpose, but do you
know that what you've got there is equivalent to