Module: AASM::Persistence::ActiveRecordPersistence::InstanceMethods
- Defined in:
- lib/aasm/persistence/active_record_persistence.rb
Instance Method Summary collapse
-
#aasm_write_state(state, name = :default) ⇒ Object
Writes
stateto the state column and persists it to the database. -
#aasm_write_state_without_persistence(state, name = :default) ⇒ Object
Writes
stateto the state column, but does not persist it to the database.
Instance Method Details
#aasm_write_state(state, name = :default) ⇒ Object
Writes state to the state column and persists it to the database
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
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/aasm/persistence/active_record_persistence.rb', line 54 def aasm_write_state(state, name=:default) old_value = read_attribute(self.class.aasm(name).attribute_name) aasm_write_attribute state, name success = if aasm_skipping_validations(name) value = aasm_raw_attribute_value(state, name) aasm_update_column(name, value) else self.save end success ? true : aasm_rollback(name, old_value) end |
#aasm_write_state_without_persistence(state, name = :default) ⇒ Object
Writes state to the state column, but does not persist it to the database
foo = Foo.find(1)
foo.aasm.current_state # => :opened
foo.close
foo.aasm.current_state # => :closed
Foo.find(1).aasm.current_state # => :opened
foo.save
foo.aasm.current_state # => :closed
Foo.find(1).aasm.current_state # => :closed
NOTE: intended to be called from an event
80 81 82 |
# File 'lib/aasm/persistence/active_record_persistence.rb', line 80 def aasm_write_state_without_persistence(state, name=:default) aasm_write_attribute(state, name) end |