0

我在应用程序中有以下状态机:

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

4

1 回答 1

1

你可以这样尝试:

编辑:根据您的评论

 before_save do |w| 
     w.transition_to_awaiting_review if w.changes['attr_name']
 end

 event :transtion_to_awaiting_review do
    transition all => :awaiting_review
 end 

这只会在模型的特定属性发生变化时更新。

于 2012-11-24T16:41:27.897 回答