Archive for November, 2007

A few things I learned about ActiveRecord after_create (and other callbacks)

1. after_create does not get inherited
class Animal < ActiveRecord::Base
after_create :feed_on_milk
def feed_on_milk
self.immunity_level += 1
end
end
class Cat < Animal
end
The after_create does not get inherited, and so our poor little cats won’t get milk! To retain the after_create hook, you’ll need to do:
class Cat < Animal
after_create :feed_on_milk
end
2. after_create is an array of symbols
If you call after_create on same […]