我使用工作流作为状态机。我想在每次更新后将状态移动到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)
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