我已经在应用以下状态机:如何在更新对象后总是将状态更改为awaiting_review?
class Cv < ActiveRecord::Base
include Workflow
workflow do
state :new do
event :submit, :transitions_to => :awaiting_review
end
state :awaiting_review do
event :review, :transitions_to => :being_reviewed
end
state :being_reviewed do
event :accept, :transitions_to => :accepted
event :reject, :transitions_to => :rejected
end
state :accepted
state :rejected
end
def submit
halt unless valid?
end
end
# cvs_controller.rb
def update
@cv = Cv.find(params[:id])
if @cv.update_attributes(params[:cv])
# @cv.back_to_review!
redirect_to root_path
end
end
我想移动状态awaiting_review
总是后,我更新的对象。
所以我应该在每个状态块中添加event :back_to_review!, :transitions_to => :awaiting_reviewed
??
我使用这种宝石:https://github.com/geekq/workflow
你使用ActiveRecord吗? – Shtirlic
是的,我喜欢。这是Rails应用程序。 – tomekfranek
也许你应该定义AR after_update回调calliting事件awaiting_review – Shtirlic