Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

How to hook into callbacks from observer?

#21

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.

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

State: new
Milestone: none
Assigned to: Scott Barron Scott Barron

Activity

  1. Karim Helal
    Karim Helal

    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

    January 21st, 2010 @ 07:35 AM

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.