开发者

rails 3 before_update callback

开发者 https://www.devze.com 2023-04-12 12:56 出处:网络
I have a model with before_update cal开发者_如何学JAVAlback def if !condition #not update record end

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

精彩评论

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