开发者

Custom validation :on => :create not working

I have a custom validation method that I only want executed on create:

validate :post_count, :on => :create

def post_count开发者_如何转开发
  # validate stuff
end  

However, it's getting fired on update (in addition to on create).

Does the :on => :create option not work with custom validation methods?


As far as I know, there's no :on option. Use

validate_on_create :post_count

instead. And there's validate_on_update also. You can read about this methods here.


This may be a Rails 2.x vs. Rails 3 issue but according to the Rails Guides on Validation the :on option is definitely valid (though I am fighting with why it's not firing for me in a similar way).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜