开发者

rails 3 before_update callback

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜