# Validation on different actions

**URL:** <https://www.ruby-forum.com/t/validation-on-different-actions/103344>\
**Category:** Rails\
**Created:** [May 4, 2007, 3:45pm UTC](https://www.ruby-forum.com/t/validation-on-different-actions/103344 "2007-05-04T15:45:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_McAuley](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/71e660/32.png) [@John\_McAuley](https://www.ruby-forum.com/u/John_McAuley)\
**Post date:** [May 4, 2007, 3:45pm UTC](https://www.ruby-forum.com/t/validation-on-different-actions/103344/1 "2007-05-04T15:45:38Z")

</div>

Hello Everyone,

I have a User model which uses validation helpers as follows:

Model User

1. validates\_presence\_of :name, :email
2. validates\_presence\_of :password, :password\_confirmation,

When the user is created by the administrator, I want the first  
validation  
to be triggered (1). But when the user is updated, (ie the password  
added  
by the user on login), I want the second validation to be triggered (2).  
So  
on creation the administrator is obliged to enter name and email, but  
when  
the user logs in for the first time, they are obliged to change their  
password. I am using active record and would like to stick to this mode  
of  
use if possible. The other option is to create two models, one for  
update  
and one for create but it seems a little superfluous. Has anyone any  
ideas?

Thanks,

j

---

<div class="post-metadata">

**Author:** ![John\_McAuley](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/71e660/32.png) [@John\_McAuley](https://www.ruby-forum.com/u/John_McAuley)\
**Post date:** [May 4, 2007, 4:35pm UTC](https://www.ruby-forum.com/t/validation-on-different-actions/103344/2 "2007-05-04T16:35:50Z")

</div>

You should be able to do this:

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

This should make it so that they only get called as you specified.
