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

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community 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 =>
'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) :-)

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

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