protecting attributes using state_machine
I'm trying to protect updates to certain attributes using state_machine
but I can't seem to get it to work correctly.
I want to LOCK updates on certain attributes when the state is completed
But instead of firing on STATE completed it fires during the transition to
completed as well... meaning before the state has finished, preventing the
state entirely!
eg
## BLOCK CHANGES MADE IN COMPLETED OR FAILED STATE
validate :lock_down_attributes_when_published, :if => Proc.new { |log|
log.state?(:completed) }
or
validate :lock_down_attributes_when_published, :if => Proc.new { |log|
log.completed? }
with
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
It's
No comments:
Post a Comment