I have a model with before_update cal开发者_如何学JAVAlback
def
if !condition
#not update record
end
end
I need this not update thing, how to prevent model update?
Use a custom validator. You can't prevent updating a record from a before_update
self.errors.add(:base, "Some error message")
return false
I don't think that before update callbacks are a good place to add validation code. You can do the same with the validates_each.
精彩评论