当尝试将模型中的一个列值设置为nil时,Rail的ActiveRecord是否有任何特殊规则?
freez方法中的健全性检查总是失败。
模型:项目
列: non_project_costs_value (可为空的十进制字段)
def froz?
return !(non_project_costs_value.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
发布于 2009-12-21 04:58:32
你的freez方法中有一个bug
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
https://stackoverflow.com/questions/1938247
复制