嗨,我正在尝试为模型编写自定义验证,如果验证失败,则不允许保存模型。
这是我到目前为止所拥有的:
validate :valid_est_time
private
def valid_est_time
if !self.est_time.is_a? Integer || self.est_time >= 0
self.errors.add("Invalid Response Estimated Time.")
end
end
验证通过不保存模型来工作,但它也会引发错误(我不希望它这样做)
NoMethodError in Jobs#index
Showing /Users/squitorio/Documents/Project/Dispatcher/assist/app/views/jobs/_index_active.html.erb where line #19 raised:
undefined method `minutes' for nil:NilClass
我只是希望它不保存模型,然后继续