Forum: Ruby on Rails Validation on different actions

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
John McAuley (Guest)
on 2007-05-04 17:45
(Received via mailing list)
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
to be triggered (1).  But when the user is updated, (ie the password
by the user on login), I want the second validation to be triggered (2).
on creation the administrator is obliged to enter name and email, but
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
use if possible.  The other option is to create two models, one for
and one for create but it seems a little superfluous.  Has anyone any


monki (Guest)
on 2007-05-04 18:35
(Received via mailing list)
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.
This topic is locked and can not be replied to.