How do I access old and new states in an aasm callback in rails?

1.9k Views Asked by At

I am new to both Ruby and Rails.

I'm using AASM to put state machine behavior into a model class. Depending on the old and new states I want to handle the state change event in different ways.

How do I either invoke the "after" callback with the "to" and "from" states as arguments or access the internal fields of held by AASM if those have what I need? ...or do I just have to add both before and after callbacks and save the previous state in the before callback?

1

There are 1 best solutions below

0
On

You can access ModelClass.aasm_state()

If you have different transitions for different states.

Aasm is pretty well documented. You can find the instructions in the README for aasm: https://github.com/rubyist/aasm

state :dating,   :enter => :make_happy,        :exit => :make_depressed

def make_happy
  # do something
end

...