# Problem loading plugin that depends on another plugin

**URL:** <https://www.ruby-forum.com/t/problem-loading-plugin-that-depends-on-another-plugin/172993>\
**Category:** Rails\
**Created:** [July 30, 2009, 10:23pm UTC](https://www.ruby-forum.com/t/problem-loading-plugin-that-depends-on-another-plugin/172993 "2009-07-30T22:23:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [July 30, 2009, 10:23pm UTC](https://www.ruby-forum.com/t/problem-loading-plugin-that-depends-on-another-plugin/172993/1 "2009-07-30T22:23:08Z")

</div>

I am trying to extract some code I have written into a plugin (an  
engine actually, since I want to share the views to new apps). I  
really like the organization I see in the new Clearance engine - esp  
with respect to how they organize testing of the engine + testing the  
integration of the engine into your app (http://  
[Clearance Is A Rails Engine](http://giantrobots.thoughtbot.com/2009/4/22/clearance-is-a-rails-engine)). So  
I have been following their method of creating modules and then  
including those modules into models so that things are well set up for  
overriding in the enclosing app. This was going well for the first  
couple models - and then I tried to convert my photo model that  
depends on attachment\_fu.

module Experts  
module Photo

```
def self.included(model)
  # model.send(:include,

```

ClassMethods)  
model.send(:include, Callbacks)  
model.send(:include, Relationships)  
model.send(:include, Validations)  
end

```
module CallBacks
  has_attachment :storage => :file_system, :path_prefix => 'public/

```

photos’,  
:content\_type =\> :image,  
:min\_size =\> 1.kilobyte, :max\_size =\> 3.megabyte,  
:thumbnails =\> {:thumbnail =\> ‘x100\>’}  
end  
…  
end  
end

The server will not start. Initially this complained

vendor/plugins/experts/lib/experts/photo.rb:15: undefined method  
`has\_attachment’ for Experts::Photo::CallBacks:Module (NoMethodError)

So I changed the file that is called when my experts plugin is  
initialized to include methods from the attachment\_fu plugin.

require ‘technoweenie/attachment\_fu’  
include Technoweenie::AttachmentFu::ActMethods

This changed the error to:

vendor/plugins/attachment\_fu/lib/technoweenie/attachment\_fu.rb:180:in  
`extended': undefined method `class\_inheritable\_accessor’ for  
Experts::Photo::CallBacks:Module (NoMethodError)

Following this back, class\_inheritable\_accessor is a Rails extension  
to Class from activesupport/lib/active\_support/core\_ext/class/  
inheritable\_attributes.rb

I am a little stumped at how to make sure those methods are available  
when my plugin is loaded. Attachment\_fu loads just fine without  
explicitly requiring active\_support (though I do see that the  
CoreImage stuff in its vendor directory does have a “require  
‘active\_support’” line.) But I tried adding that to my initialization  
file just to see; it did not help.

The default plugin load order says it is alphabetical, so  
attachment\_fu should be loaded before experts. Specifying the load  
order using config.plugins in the enclosing app does not help.

The bottom line is I don’t understand plugin loading. Can someone give  
me some pointers? The part I find most puzzling is why attachment\_fu  
loads when used in an app but my plugin that depends on it can’t.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [July 30, 2009, 10:58pm UTC](https://www.ruby-forum.com/t/problem-loading-plugin-that-depends-on-another-plugin/172993/2 "2009-07-30T22:58:15Z")

</div>

On Jul 30, 4:21 pm, cnk [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> The server will not start. Initially this complained
> 
> vendor/plugins/experts/lib/experts/photo.rb:15: undefined method  
> `has\_attachment’ for Experts::Photo::CallBacks:Module (NoMethodError)
> 
> So I changed the file that is called when my experts plugin is  
> initialized to include methods from the attachment\_fu plugin.

> The bottom line is I don’t understand plugin loading. Can someone give  
> me some pointers? The part I find most puzzling is why attachment\_fu  
> loads when used in an app but my plugin that depends on it can’t.

plugin loading is a red herring here. The problem is that  
has\_attachment is being called on the Experts::Photo::CallBacks module  
rather than on an activerecord class. You need to be doing this call  
from your self.included callback

Fred

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [July 30, 2009, 11:17pm UTC](https://www.ruby-forum.com/t/problem-loading-plugin-that-depends-on-another-plugin/172993/3 "2009-07-30T23:17:00Z")

</div>

On Jul 30, 1:57 pm, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> plugin loading is a red herring here. The problem is that  
> has\_attachment is being called on the Experts::Photo::CallBacks module  
> rather than on an activerecord class. You need to be doing this call  
> from your self.included callback

I don’t know that I would call it a red herring - more like a symptom  
of not really understanding how to stitch things together. If I  
understand you correctly, has\_attachment can’t be a module callback.  
It almost isn’t a part of the module at all. Rather it is something  
the module needs to add to the AR-derived class that is including my  
module. Yes?

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [July 30, 2009, 11:39pm UTC](https://www.ruby-forum.com/t/problem-loading-plugin-that-depends-on-another-plugin/172993/4 "2009-07-30T23:39:48Z")

</div>

Oh now I see - I had just parked code into the module - not within a  
method. Dho!

With Fred’s pointer and some experimentation, I now have files  
uploading from my plugin code. The has\_attachment code actually needed  
to go into ClassMethods, like so:

```
module ClassMethods
  def self.included(model)
    model.class_eval do
      has_attachment :storage => :file_system, :path_prefix =>

```

‘public/photos’,  
:content\_type =\> :image,  
:min\_size =\> 1.kilobyte, :max\_size =\>  
3.megabyte,  
:thumbnails =\> {:thumbnail =\> ‘x100\>’}  
end  
end  
end

Have a couple more things to play with - and then I need to see if I  
can use has\_many\_polymorphs within my included modules.

Thanks Fred!
