You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Condition on an event doesn't take method name symbol as indicated in the documentation
class Thing < ActiveRecord::Base
include Workflow
workflow do
state :on do
event :turn_off, transitions_to: :off
end
state :off do
event :turn_on, transitions_to: :on, if: :has_power
end
end
def has_power
power > 0
end
def turn_on
halt!('cannot turn on') unless check
end
end
Thing.new # => TypeError: condition must be nil or callable (eg. a proc or lambda)
with 1.2.0
The text was updated successfully, but these errors were encountered:
Yeah, the documentation still needs to be corrected. The conditional event transitions should only show the proc example.
For anyone who wants to use the same proc in multiple places (like an instance method), you can store the proc to a constant like this:
TRANSITIONS_TO_ANOTHER_STATE = proc do |record|
record.should_transition?
end
workflow do
state :default do
event :something_happened, transitions_to: :another_state, if: TRANSITIONS_TO_ANOTHER_STATE
end
end
Condition on an event doesn't take method name symbol as indicated in the documentation
with 1.2.0
The text was updated successfully, but these errors were encountered: