Forum: Ruby on Rails Advanced Plugin Development Question

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
E3640176765dae2465d33ef6eb114691?d=identicon&s=25 (Guest)
on 2007-03-13 15:38
(Received via mailing list)
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 topic is locked and can not be replied to.