I didn't use changes
method. But I'm sure that you always can use magic methods <attribute_name>_changed?
and <attribute_name>_was
:
services.any? {|s| s.attribute_name_changed?}
services.map(&:attribute_name_was)
See Ryan Bates's railscast for more information: #109 episode
UPDATE: You can pass :after_delete
, and :after_add
callbacks to has_many
association directly:
has_many :items, :after_add => :my_method_or_proc1, :after_remove => :my_method_or_proc2
Be careful using these callbacks and pay attention how they work. They
are called on items.build
and items.create
once. So if you call
items.build
and then save parent object (with nested attributes for
example) after_add
callback will be called only once on building
associated object. It means that if parent has validation then built items
won't be saved in the database and you can't rely on after_add
callback. In other words it doesn't say that added association's record was saved in the DB. So you have guarantee that item is added and saved only on call items.create
. I hope you understand this clarification.
services
association). What am I doing wrong? – Cannibalism