#21 new
James Bebbington

How to hook into callbacks from observer?

Reported by James Bebbington | November 23rd, 2009 @ 10:13 AM

Hi,

I'm looking to move some non-buisness logic out of a couple of models and into an observer. Is it possible to hook into the event callbacks from an observer? Something like this…

class Foo < ActiveRecord:base
  include AASM

  aasm_state :unpublished
  aasm_state :published, :after_enter => :do_business_thing

  aasm_initial_state :unpublished

  aasm_event :publish do
    transitions :to => :published, :from => :unpublished
  end

  def do_business_thing
    # SERIOUS BUSINESS
  end

end


class FooObserver < ActiveRecord::Observer
  observe :foo, :bar

  def after_publish
    # FRIVOLOUS BUSINESS
  end
end

Thanks.

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

Library for adding state machines to Ruby classes. Includes persistence layers for things like ActiveRecord. Formerly known as acts_as_state_machine.

People watching this ticket

Pages