Forum: Ruby on Rails skip validation

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.
407763800e3c974985dc805ef8f2b8cb?d=identicon&s=25 Pradeep Maddi (pradeep)
on 2007-05-25 17:00
Hi all,

In user model i have 4 validations. In an update i need to skip 2 of
those validations and other 2 need to fire.

Please help how to do that.

Thanks in advance
0ab6a5abab167b409f58d280dc59a229?d=identicon&s=25 Faisal N Jawdat (Guest)
on 2007-05-25 17:09
(Received via mailing list)
On May 25, 2007, at 11:00 AM, Pradeep Maddi wrote:
> In user model i have 4 validations. In an update i need to skip 2
> of those validations and other 2 need to fire.

:on => create

407763800e3c974985dc805ef8f2b8cb?d=identicon&s=25 Pradeep Maddi (pradeep)
on 2007-05-25 17:22
Faisal N Jawdat wrote:
> On May 25, 2007, at 11:00 AM, Pradeep Maddi wrote:
>> In user model i have 4 validations. In an update i need to skip 2
>> of those validations and other 2 need to fire.
> :on => create
> -faisal

Thanks for your response....

let me give detail information

i have validations on email, password, password length etc...

i have the following methods

1. signup
2. forgot password
3. change password

In the above 3 scenarios i am using save and update methods here both
validations should exist

4. Update user (no password field)

In this scenario i need to skip the password validation for length

plz help me
588ab1c0a5610a7e160a3b101abb91e6?d=identicon&s=25 MichaelLatta (Guest)
on 2007-05-25 19:41
(Received via mailing list)
This does not sound right to me.

WHen you save a user object you should either have a password or not
have one.  If you allow the user to exist with no password then your
validations should be done conditionally in your validate method.
But, I would not allow a user to exist without a password, that is a
bad security setup.  Validations happen at the model level not the
form level, so you are validating the entire user record not just the
fields being changed by a form.

If I misunderstood your situation pleas include more detail.


On May 25, 8:22 am, Pradeep Maddi <>
21f7ed21f11a809050594c82eab11d67?d=identicon&s=25 Robert Walker (Guest)
on 2007-05-25 21:15
(Received via mailing list)
First a more direct answer to your question:

ActiveRecord supplies validate_on_create and validate_on_update as
separate methods from validate.  If you really wanted validation of
creation of objects, but not on update you could put your validation
in validate_on_create.

However, it sounds like you have a fundamental misunderstanding of
validation (as eluded to in a previous reply).  If you are validating
a user's password for presence and length then you should always
perform that check.

class User < ActiveRecord::Base
  validates_presence_of :username, :password
  validates_length_of :password, :minimum => 6

    #put your create validations here

    #put your update validations here

It almost sounds like you are validating somewhere else besides the
model.  If you are doing that then....well don't.  What happens if
records are inserted or updated without going through your view or
D7661d89881d8f0b633bcf97f8d7235e?d=identicon&s=25 Jet (Guest)
on 2007-05-26 15:29
(Received via mailing list)
from what i have understood:
firstly u need to get a instance of the user you want to update
@user = users.find( :first, :conditions => { :id => your id} )
 now update the instance and call update on this instance
the validations are already in the right place so no need to change


On May 25, 8:22 am, Pradeep Maddi <>
Db7238007950074e9e73b76a81910406?d=identicon&s=25 tonypm (Guest)
on 2007-08-16 08:35
(Received via mailing list)

I appreciate that this is an old post, but I have just come across
what I think is the same situation. I have a role attribute in my
user, and allow the role to be changed.   To allow this, I was using
update_attribute_with_validation_skipping,  so that the lack of
confirmation password field error would not occur.  Since role was
coming from a select, this was fairly ok.

However, I now want to add other attributes which the admin user needs
to be able to change.  It would be nice to add validation to these
fields, but then I cannot use validation skipping.

I just wondered if you had come up with a neat solution, or if others
had any ideas.  The two possibilities I can see are:

a.  Continue to use validation skipping and write my own validation
checks in the controller (or in the model, but I am not sure how I
would trigger them there).
b.  Put the additional attributes in a separate 'has and belongs to
one' model.

This topic is locked and can not be replied to.