Methods
Public Instance methods
Returns the value of the aasm_column - called from aasm_current_state
If it‘s a new record, and the aasm state column is blank it returns the initial state:
class Foo < ActiveRecord::Base
include AASM
aasm_column :status
aasm_state :opened
aasm_state :closed
end
foo = Foo.new
foo.current_state # => :opened
foo.close
foo.current_state # => :closed
foo = Foo.find(1)
foo.current_state # => :opened
foo.aasm_state = nil
foo.current_state # => nil
NOTE: intended to be called from an event
This allows for nil aasm states - be sure to add validation to your model
[ show source ]
# File lib/persistence/active_record_persistence.rb, line 182
182: def aasm_read_state
183: if new_record?
184: send(self.class.aasm_column).blank? ? self.class.aasm_initial_state : send(self.class.aasm_column).to_sym
185: else
186: send(self.class.aasm_column).nil? ? nil : send(self.class.aasm_column).to_sym
187: end
188: end