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.
99f81a956dee7db6f6449c78f2ca8e39?d=identicon&s=25 Dan Paul (Guest)
on 2009-02-11 20: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.
2505b282d57c29be797dc35b245adb4c?d=identicon&s=25 Philip Hallstrom (Guest)
on 2009-02-11 21: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
99f81a956dee7db6f6449c78f2ca8e39?d=identicon&s=25 Dan Paul (Guest)
on 2009-02-12 07:47
(Received via mailing list)
hey thanks that was the trick, much appreciated
99f81a956dee7db6f6449c78f2ca8e39?d=identicon&s=25 Dan Paul (Guest)
on 2009-02-12 07:48
(Received via mailing list)
hey thanks that was the trick, much appreciated
This topic is locked and can not be replied to.