Validation :on => :update


#1

I would like to validate a model on several events. I have:

validates_numericality_of :ships_in, :on => :update, :message =>
‘xyz…’

I have this validating on update, but I also want it to validate on save
and on create as well.

Do I have to duplicate this validator for each event? or is there
something cool i can do like:

:on => [:update, :save, :create]
(which doesn’t work) :slight_smile:

Thanks for your help!

Dave C


#2

If you get rid of the “:on => …” it will work for all of them. :slight_smile:

-Adam


#3

Adam B. wrote:

If you get rid of the “:on => …” it will work for all of them. :slight_smile:

-Adam

That’s crazy talk. :slight_smile:

Took the api doc too literally:

on - Specifies when this validation is active (default is :save, other
options :create, :update)

I assumed the default would only apply to save.

Thanks Adam!!