bcparanj-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Mar-13 14:37 UTC
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 => 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. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---