Method: AASM::Persistence::DynamoidPersistence::InstanceMethods#aasm_write_state
- Defined in:
- lib/aasm/persistence/dynamoid_persistence.rb
#aasm_write_state(state, name = :default) ⇒ Object
Writes state to the state column and persists it to the database using update_attribute (which bypasses validation)
foo = Foo.find(1)
foo.aasm.current_state # => :opened
foo.close!
foo.aasm.current_state # => :closed
Foo.find(1).aasm.current_state # => :closed
NOTE: intended to be called from an event
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/aasm/persistence/dynamoid_persistence.rb', line 39 def aasm_write_state(state, name=:default) old_value = read_attribute(self.class.aasm(name).attribute_name) write_attribute(self.class.aasm(name).attribute_name, state.to_s) unless self.save(:validate => false) write_attribute(self.class.aasm(name).attribute_name, old_value) return false end true end |