我正在尝试使用state_machine保护对某些属性的更新,但我似乎无法让它正常工作。
当状态为时,我想锁定某些属性的更新completed
但是它不是在状态completed
上触发,而是在过渡到完成期间触发......意思是在状态完成之前,完全阻止状态!
例如
## BLOCK CHANGES MADE IN COMPLETED OR FAILED STATE
validate :lock_down_attributes_when_published, :if => Proc.new { |log| log.state?(:completed) }
或者
validate :lock_down_attributes_when_published, :if => Proc.new { |log| log.completed? }
和
private
def lock_down_attributes_when_published
return unless completed?
message = "must not change when #{state}"
errors.add(:head_count, message) if head_count_changed?
errors.add(:quiz_master_id, message) if quiz_master_id_changed?
errors.add(:qm_fee, message) if qm_fee_pennies_changed?
errors.add(:total_fee, message) if total_fee_pennies_changed?
end
它是