Forum: Ruby on Rails validates_presence_of - only on edit

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.
Dan P. (Guest)
on 2009-02-11 21:51
(Received via mailing list)
Ok so not sure if this is possible but it would help out a lot if it
is.  I am trying to put this validation on one of my forms

validates_presence_of :name, :state

however I only need this validation to run when they edit this form,
not when they create it. is this possible, any suggestions would be
greatly appreciated. thanks in advance.
Philip H. (Guest)
on 2009-02-11 22:09
(Received via mailing list)
> Ok so not sure if this is possible but it would help out a lot if it
> is.  I am trying to put this validation on one of my forms
>
> validates_presence_of :name, :state
>
> however I only need this validation to run when they edit this form,
> not when they create it. is this possible, any suggestions would be
> greatly appreciated. thanks in advance.

Check the docs... it's in there.

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

validates_presence_of :name, :state, :on => :update

-philip
Dan P. (Guest)
on 2009-02-12 08:47
(Received via mailing list)
hey thanks that was the trick, much appreciated
Dan P. (Guest)
on 2009-02-12 08:48
(Received via mailing list)
hey thanks that was the trick, much appreciated
This topic is locked and can not be replied to.