# Plugin: include vs. base.send :include

**URL:** <https://www.ruby-forum.com/t/plugin-include-vs-base-send-include/134705>\
**Category:** Rails\
**Created:** [April 14, 2008, 10:02am UTC](https://www.ruby-forum.com/t/plugin-include-vs-base-send-include/134705 "2008-04-14T10:02:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bazzel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/76d3ee/32.png) [@bazzel](https://www.ruby-forum.com/u/bazzel)\
**Post date:** [April 14, 2008, 10:02am UTC](https://www.ruby-forum.com/t/plugin-include-vs-base-send-include/134705/1 "2008-04-14T10:02:51Z")

</div>

Hello all,

I’ve created a simple plugin to extend the functionality of my  
controllers. So in my plugins//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’?

Thanks in advance.

(I’m using Rails 1.2.6).

---

<div class="post-metadata">

**Author:** ![bazzel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/76d3ee/32.png) [@bazzel](https://www.ruby-forum.com/u/bazzel)\
**Post date:** [April 14, 2008, 11:13am UTC](https://www.ruby-forum.com/t/plugin-include-vs-base-send-include/134705/2 "2008-04-14T11:13:27Z")

</div>

On 14 Apr 2008, at 09:02, Patrick B. wrote:

> 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

module MyPlugin  
def some\_method  
end  
end  
)

---

<div class="post-metadata">

**Author:** ![bazzel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/76d3ee/32.png) [@bazzel](https://www.ruby-forum.com/u/bazzel)\
**Post date:** [April 14, 2008, 11:42am UTC](https://www.ruby-forum.com/t/plugin-include-vs-base-send-include/134705/3 "2008-04-14T11:42:39Z")

</div>

Hi Frederick,

Thanks so much for your response. It made it all so much clearer, and, I  
must admit, now reading your explanation, I’ve had to figure it out  
myself…

There is no reason for using ‘base.send :include’ instead of just  
including the module. To be honest, I changed my code to your  
suggestion.

Patrick
