Forum: Ruby on Rails validation :on => :update....

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Dave C. (Guest)
on 2006-04-19 05:42
I would like to validate a model on several events. I have:

validates_numericality_of :ships_in, :on => :update, :message =>

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

Thanks for your help!

Dave C
Adam B. (Guest)
on 2006-04-19 05:48
If you get rid of the ":on => ..." it will work for all of them. :)

Dave C. (Guest)
on 2006-04-19 05:54
Adam B. wrote:
> If you get rid of the ":on => ..." it will work for all of them. :)
> -Adam

That's crazy talk. :-)

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!!
This topic is locked and can not be replied to.