geekq / workflow

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

Workflow::NoTransitionAllowed: There is no event approve defined for the pending state #149

Closed ziweizhou closed 2 years ago

ziweizhou commented 9 years ago

I have following code,

include Workflow
  workflow do
    state :pending do
      event :approve, :transitions_to => :approved, :if => :all_approved?
      event :reject, :transitions_to => :rejected
      event :cancel, :transitions_to => :cancelled
    end
    state :approved do
      event :pay, :transitions_to => :paid
      event :book, :transitions_to => :booked
    end
    state :booked
    state :paid
    state :cancelled
    state :approved
    state :rejected

  end

when i do task.approve! I got following error.

Workflow::NoTransitionAllowed: There is no event approve defined for the pending state
    from /Users/ziweizhou/Dropbox/Development/rails/test_ror/vendor/bundle/ruby/2.1.0/bundler/gems/workflow-403a9e44bf49/lib/workflow.rb:98:in `process_event!'
    from /Users/ziweizhou/Dropbox/Development/rails/test_ror/vendor/bundle/ruby/2.1.0/bundler/gems/workflow-403a9e44bf49/lib/workflow.rb:64:in `block (4 levels) in assign_workflow'
    from (irb):2

Any idea why?

illegalnumbers commented 9 years ago

+1

deerawan commented 9 years ago

+1

kwent commented 9 years ago

+1

timbica commented 8 years ago

Well, I've an app in production that raised this problem. I tried to replicate the problem and it was due to the user clicking more than once in the action button. So, the request was done more than once, which resulted in the second one to raise the exception.