# How to update user model attributes and bypass a presence\_of validation?

**URL:** <https://www.ruby-forum.com/t/how-to-update-user-model-attributes-and-bypass-a-presence-of-validation/191862>\
**Category:** Rails\
**Created:** [July 19, 2010, 10:54pm UTC](https://www.ruby-forum.com/t/how-to-update-user-model-attributes-and-bypass-a-presence-of-validation/191862 "2010-07-19T22:54:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![diabolist](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c2a13f/32.png) [@diabolist](https://www.ruby-forum.com/u/diabolist)\
**Post date:** [July 19, 2010, 10:54pm UTC](https://www.ruby-forum.com/t/how-to-update-user-model-attributes-and-bypass-a-presence-of-validation/191862/1 "2010-07-19T22:54:34Z")

</div>

Hello, I have a user model which stores a users name, email, and  
password.

I have a separate profile controller which lets the user edit his name,  
email, and password from the user model.

I want the user to be able to update his name separately from his email  
as  
well as change his password separately from when he changes his name or  
email.

So on my profile edit page I have 3 forms. One for editing his name, one  
for  
his email, then a third form to enter in his current password, what he  
wants  
his new password to be, then a confirmation of that password.

My problem is that he can’t edit just his name, when I submit the name  
form  
the password validation kicks in and won’t let me submit.

Can anyone give me some tips on how I could accomplish this please?  
Thank  
you.

---

<div class="post-metadata">

**Author:** ![diabolist](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c2a13f/32.png) [@diabolist](https://www.ruby-forum.com/u/diabolist)\
**Post date:** [July 20, 2010, 12:10am UTC](https://www.ruby-forum.com/t/how-to-update-user-model-attributes-and-bypass-a-presence-of-validation/191862/2 "2010-07-20T00:10:40Z")

</div>

Validations usually have an :if/:unless option. That might be helpful.  
You could, for example, condition the password and e-mail values to  
validate only if the name is present.

---

<div class="post-metadata">

**Author:** ![diabolist](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c2a13f/32.png) [@diabolist](https://www.ruby-forum.com/u/diabolist)\
**Post date:** [July 20, 2010, 10:24pm UTC](https://www.ruby-forum.com/t/how-to-update-user-model-attributes-and-bypass-a-presence-of-validation/191862/3 "2010-07-20T22:24:22Z")

</div>

There is also the :on option for validations. With combining :on  
with :if you could essentially set up several validations that are  
triggered by the specific pages.

One validation to ensure presence\_of :name, :email and :password :on  
=\> :create  
One validation to ensure presence\_of :name :on =\> :update, :if  
=\> :email\_and\_password\_are\_not\_being\_updated  
One validation to ensure presence\_of :email :on =\> :update, :if  
=\> :name\_and\_password\_are\_not\_being\_updated  
One validation to ensure presence\_of :password :on =\> :update, :if  
=\> :email\_and\_name\_are\_not\_being\_updated

You would have to write the methods for each :if option to inspect the  
attribute updates being sent by the form and other validations might  
be necessary if you have another page to allow edits for all three  
attributes.

Hope this helps.

Bob

---

<div class="post-metadata">

**Author:** ![diabolist](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c2a13f/32.png) [@diabolist](https://www.ruby-forum.com/u/diabolist)\
**Post date:** [July 21, 2010, 2:04am UTC](https://www.ruby-forum.com/t/how-to-update-user-model-attributes-and-bypass-a-presence-of-validation/191862/4 "2010-07-21T02:04:32Z")

</div>

Thank you both Pepe and Bob. I appreciate it.

Andrew

---

<div class="post-metadata">

**Author:** ![diabolist](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c2a13f/32.png) [@diabolist](https://www.ruby-forum.com/u/diabolist)\
**Post date:** [July 21, 2010, 3:02am UTC](https://www.ruby-forum.com/t/how-to-update-user-model-attributes-and-bypass-a-presence-of-validation/191862/5 "2010-07-21T03:02:51Z")

</div>

why not just use “update\_attribute” ?
