2 def check_update_whitelist permitted_fields
3 attribute_names.each do |field|
4 if !permitted_fields.include?(field.to_sym) && really_changed(field)
5 errors.add field, "cannot be modified in this state (#{send(field+"_was").inspect}, #{send(field).inspect})"
10 def really_changed(attr)
11 return false if !send(attr+"_changed?")
12 old = send(attr+"_was")
14 if (old.nil? || old == [] || old == {}) && (new.nil? || new == [] || new == {})
21 def validate_state_change
22 if self.state_changed?
23 unless state_transitions[self.state_was].andand.include? self.state
24 errors.add :state, "cannot change from #{self.state_was} to #{self.state}"