# Help with validates\_presence\_of

**URL:** <https://www.ruby-forum.com/t/help-with-validates-presence-of/73611>\
**Category:** Rails\
**Created:** [October 25, 2006, 6:30pm UTC](https://www.ruby-forum.com/t/help-with-validates-presence-of/73611 "2006-10-25T18:30:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sarah\_hutchinson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f07891/32.png) [@sarah\_hutchinson](https://www.ruby-forum.com/u/sarah_hutchinson)\
**Post date:** [October 25, 2006, 6:30pm UTC](https://www.ruby-forum.com/t/help-with-validates-presence-of/73611/1 "2006-10-25T18:30:15Z")

</div>

I’m trying to specify specific instances when ‘validates\_presence\_of’  
should be used in a particular model. I looked in the docs and found  
that you can set :on to specify when the particular validation should  
occur. However, I’m not sure how that should be formatted.

What I ultimately want to do is use the validation when I am creating a  
record, but not when I am updating it.

Could someone help me out with the format here. My attempt (shown  
below) doesn’t work.

validates\_presence\_of :email, :password, { :on =\> :save, :new }

Thanks!  
Sarah

---

<div class="post-metadata">

**Author:** ![sarah\_hutchinson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f07891/32.png) [@sarah\_hutchinson](https://www.ruby-forum.com/u/sarah_hutchinson)\
**Post date:** [October 25, 2006, 7:58pm UTC](https://www.ruby-forum.com/t/help-with-validates-presence-of/73611/2 "2006-10-25T19:58:39Z")

</div>

Per documentation ([api.rubyonrails.org](http://api.rubyonrails.org))…

```
on - Specifies when this validation is active (default is :save, 

```

other  
options :create, :update)

So change :new to :create and see what happens. If you still have  
problems, then try making it two separate statements, as in…

```
validates_presence_of :email, :on => :save, :create
validates_presence_of :password, :on => :save, :create

```

c.

sarah\_hutchinson wrote:

> I’m trying to specify specific instances when ‘validates\_presence\_of’  
> should be used in a particular model. I looked in the docs and found  
> that you can set :on to specify when the particular validation should  
> occur. However, I’m not sure how that should be formatted.
> 
> What I ultimately want to do is use the validation when I am creating a  
> record, but not when I am updating it.
> 
> Could someone help me out with the format here. My attempt (shown  
> below) doesn’t work.
> 
> validates\_presence\_of :email, :password, { :on =\> :save, :new }
> 
> Thanks!  
> Sarah

---

<div class="post-metadata">

**Author:** ![sarah\_hutchinson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f07891/32.png) [@sarah\_hutchinson](https://www.ruby-forum.com/u/sarah_hutchinson)\
**Post date:** [October 25, 2006, 8:01pm UTC](https://www.ruby-forum.com/t/help-with-validates-presence-of/73611/3 "2006-10-25T20:01:24Z")

</div>

Sorry - clicked submit too quickly… you don’t want the :save in  
there…

validates\_presence\_of :email, :password, :on =\> :create

or

validates\_presence\_of :email, :on =\> :create  
validates\_presence\_of :password, :on =\> :create

should work.  
c.

Cayce B. wrote:

> Per documentation ([api.rubyonrails.org](http://api.rubyonrails.org))…
> 
> ```
> on - Specifies when this validation is active (default is :save, 
> 
> ```
> 
> other  
> options :create, :update)
> 
> So change :new to :create and see what happens. If you still have  
> problems, then try making it two separate statements, as in…
> 
> ```
> validates_presence_of :email, :on => :save, :create
> validates_presence_of :password, :on => :save, :create
> 
> ```
> 
> c.
> 
> sarah\_hutchinson wrote:
> 
> > I’m trying to specify specific instances when ‘validates\_presence\_of’  
> > should be used in a particular model. I looked in the docs and found  
> > that you can set :on to specify when the particular validation should  
> > occur. However, I’m not sure how that should be formatted.
> > 
> > What I ultimately want to do is use the validation when I am creating a  
> > record, but not when I am updating it.
> > 
> > Could someone help me out with the format here. My attempt (shown  
> > below) doesn’t work.
> > 
> > validates\_presence\_of :email, :password, { :on =\> :save, :new }
> > 
> > Thanks!  
> > Sarah

---

<div class="post-metadata">

**Author:** ![sarah\_hutchinson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f07891/32.png) [@sarah\_hutchinson](https://www.ruby-forum.com/u/sarah_hutchinson)\
**Post date:** [October 29, 2006, 3:28pm UTC](https://www.ruby-forum.com/t/help-with-validates-presence-of/73611/4 "2006-10-29T15:28:53Z")

</div>

Figured I’d follow this up myself since I found the answer myself. The  
correct format should have been:

validates\_presence\_of :vf\_email, :password, :on =\> :create

Cheers,  
Sarah
