0

我使用工作流作为状态机。我想在每次更新后将状态移动到,awaiting_review但我也有current_sign_in_at属性在用户登录后他的状态更改为awaiting_review如何避免这种情况?

before_save :needs_review, on: :update

# before_save
def needs_review
  self.state = 'awaiting_review' unless state_changed?
end

workflow do
  state :awaiting_review do
    event :accept, :transitions_to => :accepted
    event :reject, :transitions_to => :rejected
  end
  state :accepted do
    event :reject, :transitions_to => :rejected
  end
  state :rejected
end
#  sign_in_count          :integer          default(0)
#  current_sign_in_at     :datetime
#  last_sign_in_at        :datetime
#  current_sign_in_ip     :string(255)
#  last_sign_in_ip        :string(255)
4

1 回答 1

0
def needs_review
  if (%w[sign_in_count current_sign_in_at last_sign_in_at ...] & changes).empty?
    self.state = 'awaiting_review' unless state_changed?
  end
end
于 2013-02-15T00:03:14.097 回答