Does Rail's ActiveRecord have any special rules when attempting to set one of the column values in the model to nil?
The sanity check in the method freez always fails.
Model: Project
Column: non_project_costs_value (nullable decimal field)
def froz?
return !(non_project_costs_valu开发者_运维技巧e.nil?)
end
def freez(val)
raise 'Already frozen, cannot freeze ... the value is ' + non_project_costs_value.to_s if froz?
non_project_costs_value = val
save
raise 'Sanity check. After freezing the thing should be frozen!' if !froz?
end
You have a bug in your freez method
non_project_costs_value = val # this is setting a local variable
# (in the method freez) to val
# change to:
self.non_project_costs_value = val # this will set the record's attribute
# (the column) to val
# It will be saved to the dbms once you save
精彩评论