views:

37

answers:

2

Hi, I have a class heirarchy as follows:

class A < ActiveRecord::Base
  after_create { |i|
    #do something
  }
end

class B < A
  after_create { |i|
    #do something else after what A did
  }
end

I want to have A's behavior performed in B when after_create is invoked, but I am not sure of the proper way to write the after_create method in B.

+1  A: 

You can call the superclass version of a method using "super," like this:

class B < A
  def after_create
    super
    #now do something else after what A did
  end
end
Rob Davis
That's really useful. This and Francois's answer both work. Thanks for the answer.
Paul Gibler
+1  A: 

Each callback you define will be called, in order. You don't have anything special to do to get the behavior you want. The syntax you used is the correct one.

François Beausoleil
Great, thanks so much.
Paul Gibler