This is a note to self. Remember to define all states for an object before you start referencing it.
If not, you will get an error like this:
“You have a nil object when you didn’t expect it! The error occurred while evaluating nil.entering”
This is the solution:
1 2 3 4 5 6 7 8 9 10 11 | class Squad < ActiveRecord::Base acts_as_state_machine :initial => :in_progress event :complete do transitions :from => :in_progress, :to => :completed, :guard => Proc.new {|s| !s.completed_at.blank? } end state :in_progress # This is the line I had forgotten to write state :completed, :enter => :do_complete |
Have fun with acts_as_state_machine!
And keep in mind that acts_as_state_machine is not concurrent. Read more here.
