# Prevent fields from being validated

**URL:** <https://www.ruby-forum.com/t/prevent-fields-from-being-validated/74417>\
**Category:** Rails\
**Created:** [November 6, 2006, 3:58pm UTC](https://www.ruby-forum.com/t/prevent-fields-from-being-validated/74417 "2006-11-06T15:58:21Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![andreas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ee7513/32.png) [@andreas](https://www.ruby-forum.com/u/andreas)\
**Post date:** [November 6, 2006, 3:58pm UTC](https://www.ruby-forum.com/t/prevent-fields-from-being-validated/74417/1 "2006-11-06T15:58:21Z")

</div>

Hi all,

when my user edit its account - he can leave the password field blank to  
leave the used password untouched.

but he cant leave it blank - because the validation process in my user  
modell validates the password field all the way and throws of course an  
error if the user leave it blank.

I also have a password\_confirmation field that only needs to validat if  
a password is given.

validates\_confirmation\_of :password  
validates\_presence\_of :password

I read something from  
attr\_accessor :password

but I dont understand the function of this attribute

How can I go around this?

I am happy for any help  
thanks  
Andreas

---

<div class="post-metadata">

**Author:** ![andreas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ee7513/32.png) [@andreas](https://www.ruby-forum.com/u/andreas)\
**Post date:** [November 6, 2006, 4:15pm UTC](https://www.ruby-forum.com/t/prevent-fields-from-being-validated/74417/2 "2006-11-06T16:15:57Z")

</div>

Andreas S. wrote:

> validates\_confirmation\_of :password  
> validates\_presence\_of :password

try  
validates\_presence\_of :password, :allow\_nil =\> true

It’s not in the api doc as it relates to this specific validator, but  
it’s at the top of this page:

[http://api.rubyonrails.com/classes/ActiveRecord/Validations/ClassMethods.html#M000813](http://api.rubyonrails.com/classes/ActiveRecord/Validations/ClassMethods.html#M000813)

---

<div class="post-metadata">

**Author:** ![andreas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ee7513/32.png) [@andreas](https://www.ruby-forum.com/u/andreas)\
**Post date:** [November 6, 2006, 4:27pm UTC](https://www.ruby-forum.com/t/prevent-fields-from-being-validated/74417/3 "2006-11-06T16:27:12Z")

</div>

David C. wrote:

> try  
> validates\_presence\_of :password, :allow\_nil =\> true
> 
> It’s not in the api doc as it relates to this specific validator, but  
> it’s at the top of this page:
> 
> [Peak Obsession](http://api.rubyonrails.com/classes/ActiveRecord/Validations/ClassMethods.html#M000813)

thanks david, but this will not work - I still get the “password can’t  
be blank” error message

also, thus I use the same modell for creating a new user - than I really  
need the validation - so I cant turn it off

I wonder why nobody else ran into that problem

andreas

---

<div class="post-metadata">

**Author:** ![andreas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ee7513/32.png) [@andreas](https://www.ruby-forum.com/u/andreas)\
**Post date:** [November 6, 2006, 4:31pm UTC](https://www.ruby-forum.com/t/prevent-fields-from-being-validated/74417/4 "2006-11-06T16:31:39Z")

</div>

i found a good resource  
[http://www.ruby-forum.com/topic/60002](http://www.ruby-forum.com/topic/60002)

---

<div class="post-metadata">

**Author:** ![andreas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ee7513/32.png) [@andreas](https://www.ruby-forum.com/u/andreas)\
**Post date:** [November 7, 2006, 11:06am UTC](https://www.ruby-forum.com/t/prevent-fields-from-being-validated/74417/5 "2006-11-07T11:06:44Z")

</div>

On 11/6/06, David C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> it’s at the top of this page:
> 
> [Peak Obsession](http://api.rubyonrails.com/classes/ActiveRecord/Validations/ClassMethods.html#M000813)

There’s also the :if option, documented in the link above.

Isak

---

<div class="post-metadata">

**Author:** ![andreas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ee7513/32.png) [@andreas](https://www.ruby-forum.com/u/andreas)\
**Post date:** [November 7, 2006, 7:22am UTC](https://www.ruby-forum.com/t/prevent-fields-from-being-validated/74417/6 "2006-11-07T07:22:33Z")

</div>

Andreas S. wrote:

> thanks david, but this will not work - I still get the “password can’t  
> be blank” error message
> 
> also, thus I use the same modell for creating a new user - than I really  
> need the validation - so I cant turn it off
> 
> I wonder why nobody else ran into that problem
> 
> andreas

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