开发者

Validation, callback

I have a custom validation rule on a model that says the user can't have more than 3 records with a state of active.

validate :not_over_active_limit, :before => :create

The issue arises when I need to update one of the user's 3 active records. When I call record.update! or record.save!, a validation error is thrown saying that I can't have more than three active records. But I only want the validation to run on before_create, not on save! or update!

I can get around this by calling save(false), but I don't want to do that.

Any sugges开发者_C百科tions for handling?


The code you are looking for is

 validate :not_over_active_limit, :on => :create

Not :before but :on

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜