# Extending Rails plugins?

**URL:** <https://www.ruby-forum.com/t/extending-rails-plugins/59789>\
**Category:** Rails\
**Created:** [May 6, 2006, 5:27pm UTC](https://www.ruby-forum.com/t/extending-rails-plugins/59789 "2006-05-06T17:27:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![BA\_Baracus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e5b9ba/32.png) [@BA\_Baracus](https://www.ruby-forum.com/u/BA_Baracus)\
**Post date:** [May 6, 2006, 5:27pm UTC](https://www.ruby-forum.com/t/extending-rails-plugins/59789/1 "2006-05-06T17:27:57Z")

</div>

Gents,

I’m using the acts\_as\_taggable rails plugin (not gem), and would like to  
add some additional methods to it. For example, the find\_tagged\_with  
methods essentially does a find tag in a list (effectively an OR), while  
I’d like to implement a find\_tagged\_with\_all method that would implement  
an AND (so if I specified 4 tags, it would only return items that were  
tagged with all four inclusively).

Is there a proper way to extend a Rails plugin so that problems are  
minimized downstream when the plugin is upgraded? Or should I just dive  
right in the plugin code and hack away?

# FYR, I want to add a method to the following module:

# module SingletonMethods def find\_tagged\_with(list) find\_by\_sql(["SELECT #{table\_name}.\* FROM #{table\_name}, tags, taggings " + "WHERE #{table\_name}.#{primary\_key} = taggings.taggable\_id " + "AND taggings.taggable\_type = ? " + “AND taggings.tag\_id = tags.id AND tags.name IN (?)”, acts\_as\_taggable\_options[:taggable\_type], list ]) end end

Thanks!

## B.A.

B.A. Baracus: I thought you weren’t crazy no more?  
Murdock: Only on paper.

---

<div class="post-metadata">

**Author:** ![BA\_Baracus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e5b9ba/32.png) [@BA\_Baracus](https://www.ruby-forum.com/u/BA_Baracus)\
**Post date:** [May 6, 2006, 8:33pm UTC](https://www.ruby-forum.com/t/extending-rails-plugins/59789/2 "2006-05-06T20:33:31Z")

</div>

I put mine in a module, TagExtension (tag\_extension.rb) in the /lib  
folder. Vaguely remember there was something on rails-weenie about it  
too.  
HTH

---

<div class="post-metadata">

**Author:** ![BA\_Baracus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e5b9ba/32.png) [@BA\_Baracus](https://www.ruby-forum.com/u/BA_Baracus)\
**Post date:** [May 7, 2006, 9:39pm UTC](https://www.ruby-forum.com/t/extending-rails-plugins/59789/3 "2006-05-07T21:39:16Z")

</div>

On Saturday, May 06, 2006, at 7:32 PM, Chris T wrote:

> I put mine in a module, TagExtension (tag\_extension.rb) in the /lib  
> folder. Vaguely remember there was something on rails-weenie about it too.  
> HTH

Hmm…ok, so I’ve created my own tag\_extension.rb file in /lib, and it  
follows the same convention as the plugin:

module ActiveRecord  
module Acts #:nodoc:  
module Taggable #:nodoc:  
module SingletonMethods  
#my additional methods here  
end  
end  
end  
end

This operates under the assumption that Ruby modules are open, just as  
classes are, which based on a few irb tests they seem to be.

Now, how can I get my code to see it? The documentation says /lib files  
are loaded automagically, but this doesn’t see to be appearing in my  
models that call acts\_as\_taggable.

Thanks very much for your help!

B.A.

---

<div class="post-metadata">

**Author:** ![BA\_Baracus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e5b9ba/32.png) [@BA\_Baracus](https://www.ruby-forum.com/u/BA_Baracus)\
**Post date:** [May 7, 2006, 10:09pm UTC](https://www.ruby-forum.com/t/extending-rails-plugins/59789/4 "2006-05-07T22:09:37Z")

</div>

On Sunday, May 07, 2006, at 7:38 PM, BA Baracus wrote:

> Now, how can I get my code to see it? The documentation says /lib files  
> are loaded automagically, but this doesn’t see to be appearing in my  
> models that call acts\_as\_taggable.

I’ll answer myself here…turns out that /lib is added a load  
directory, but the files within /lib aren’t automatically loaded. To do  
this, I had to require my file in config/environment.rb:

# require plugin extension

require ‘my\_extension’

Thanks for the help!

B.A.

–  
B.A. Baracus: I thought you weren’t crazy no more?  
Murdock: Only on paper.
