i''m trying to override the push method on a habtm association, so i
can run code each time an element is added to the collection. the
module.included method is never being called when habtm includes the
module... how can i do this? or is there a better way to make a
''before_save'' listener for just the association?
class User < ActiveRecord::Base
has_and_belongs_to_many :blacklisted_users,
:class_name => ''User'',
:join_table => :blacklisted_users,
:foreign_key => :user_id,
:association_foreign_key => :blacklisted_user_id,
:insert_sql => ''insert into blacklisted_users (user_id,
blacklisted_user_id) values (#{id}, #{record.id})'',
:extend => BlacklistedUserModule
end
module BlacklistedUserModule
def self.included(base)
puts "included"
proxy_target.instance_eval do
alias_method :old_push, :<<
remove_method :<<
end
end
def <<(*args)
puts "new push"
old_push(*args)
end
end
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---