# Advanced Plugin Development Question

**URL:** <https://www.ruby-forum.com/t/advanced-plugin-development-question/88687>\
**Category:** Rails\
**Created:** [March 13, 2007, 3:38pm UTC](https://www.ruby-forum.com/t/advanced-plugin-development-question/88687 "2007-03-13T15:38:29Z")\
**Posts on this page:** 1\
**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:** [March 13, 2007, 3:38pm UTC](https://www.ruby-forum.com/t/advanced-plugin-development-question/88687/1 "2007-03-13T15:38:29Z")

</div>

I have the following code for a plugin that I am developing:

module ClassMethods  
def my\_method(child\_table)

```
      child = child_table.to_s;
      c = child.pluralize

      has_and_belongs_to_many c.to_sym,
                              :class_name => self.name,
                              :join_table => c.to_s + '_' +

```

self.name.pluralize,  
:association\_foreign\_key =\> child +  
“\_id”,  
:foreign\_key =\> self.name + “\_id”,  
:after\_add  
=\> :create\_bidirectional\_link,  
:after\_remove  
=\> :remove\_bidirectional\_link

```
      class_eval do

        define_method("create_bidirectional_link(child)") do
          child.c << self unless child.c.include?(self)
        end

        define_method("remove_bidirectional_link(child)") do
          child.c.delete(self) rescue nil
        end
      end

    end

```

When I run the code I get the following error message when I use  
my\_method in the Person model class:

NoMethodError: undefined method `create\_bidirectional\_link’ for  
#Person:0x31dd71c

How do I inject the create and remove methods to the ActiveRecord  
class? TIA.
