Advanced Plugin Development Question

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 =>,
                              :join_table => c.to_s + '_' +,
:association_foreign_key => child +
:foreign_key => + “_id”,
=> :create_bidirectional_link,
=> :remove_bidirectional_link

      class_eval do

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

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


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

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs