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
-
Karim Helal January 21st, 2010 @ 07:35 AM
Hi,
I'm trying to do the same thing using AASM. Did you find a way to do it?
Thx
.Karim Founder, CEO
Monaqasat.com
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.
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.