geekq / workflow

Ruby finite-state-machine-inspired API for modeling workflow
MIT License
1.75k stars 207 forks source link

Can I save model inside hook on_state_entry? #187

Closed deemytch closed 2 years ago

deemytch commented 8 years ago
class Meeting < ActiveRecord::Base
[skip]
def on_uploading_entry(ns, ev, *args)
  self.stopped_at = Time.now
  self.duration = new_duration
  set_some_other_fields
  ...
  self.save!
end
[skip]
end

causes

#<ActiveModel::Errors:0x00000001c5c4d8 @base=#<Meeting id: 580, [skip] >, @messages={:base=>["Cannot save myself in :uploading state."]}>