What is the best way to persist the object's state to the database on a transition using aasm? I had thought that this would happen automatically but this doesn't seem to be the case.
(Edit: when I manually save the object, the state column does get updated. But a save isn't done on transitions.)
I can't find much useful documentation for this plugin, so if you have a suggestion for an alternative finite state machine implementation with better documentation, that might help as well.
If you call the bang! form of the transition event method, the state will persist. For example, say you have an object with the following event:
class Book < ActiveRecord::Base
# ...
aasm_event :close do
transitions :to => :closed, :from => [:opened]
end
# ...
end
Calling book.close
will set the state to closed
, but will not automatically save. Calling book.close!
will set the state *and* automatically save the AR object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With