AASM gotchas

August 15, 2008

This one really got me!!

Whats wrong with the following

class Order < ActiveRecord::Base
  include AASM  
  aasm_initial_state :customer     
  aasm_column :state
  aasm_state :address      
  
  aasm_event :set_user do
    transitions :from => :customer, :to => :address
  end
   
end

The problem is that you don’t have a :customer state defined. So horrible things happen when you try and transfer using set_user

so we should have

class Order < ActiveRecord::Base
  include AASM  
  aasm_column :state

  aasm_state :customer     
  aasm_state :address      

  aasm_initial_state :customer     
  
  aasm_event :set_user do
    transitions :from => :customer, :to => :address
  end
   
end