Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 298
djburdick Avatar asked Jun 18 '10 20:06

djburdick


2 Answers

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.

like image 76
Ju Nogueira Avatar answered Oct 06 '22 00:10

Ju Nogueira


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).

like image 44
Dave Avatar answered Oct 06 '22 01:10

Dave