# Model validation giving problem

**URL:** <https://www.ruby-forum.com/t/model-validation-giving-problem/189757>\
**Category:** Rails\
**Created:** [June 7, 2010, 8:49am UTC](https://www.ruby-forum.com/t/model-validation-giving-problem/189757 "2010-06-07T08:49:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![gandhi-tush](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/5daacb/32.png) [@gandhi-tush](https://www.ruby-forum.com/u/gandhi-tush)\
**Post date:** [June 7, 2010, 8:49am UTC](https://www.ruby-forum.com/t/model-validation-giving-problem/189757/1 "2010-06-07T08:49:14Z")

</div>

Hi,  
I have a member registration form which takes a “Name”, “Login”,  
“Password”, “Confirm Password” and “Location”. In the user model I have  
added the validation  
validate\_uniqueness\_of :login, validate\_presence\_of :password, :name,  
:confirm\_password.

When the member tries to register every thing working fine. I am using  
same form for user to edit his information. When the user come to edit  
his information we are not allowing the user to edit the password so  
that we are hiding those fields.  
But whenever user adds some invalid data suppose he hasn’t added the  
“name” then the error is shown “Name should not be blank” but with that  
it also shows that “Password should not be blank”. I have checked the  
post data don’t have the password and confirm password parameter. My  
controller code is like this:-

"@member = User.find(params[:user\_id])  
@member.update\_attributes(params[:user]) "  
Can anyone have any idea how to solve this?

Thanks  
Tushar

---

<div class="post-metadata">

**Author:** ![gandhi-tush](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/5daacb/32.png) [@gandhi-tush](https://www.ruby-forum.com/u/gandhi-tush)\
**Post date:** [June 7, 2010, 9:09am UTC](https://www.ruby-forum.com/t/model-validation-giving-problem/189757/2 "2010-06-07T09:09:37Z")

</div>

Try Some thing like this On updating Yours model Code is validating  
presence  
of confirm\_password Which should not be i think.  
validate\_uniqueness\_of :login  
validate\_presence\_of :password, :name,  
validate\_confirmation\_of:confirm\_password.

On Mon, Jun 7, 2010 at 12:19 PM, Tushar G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> that we are hiding those fields.  
> Thanks  
> .  
> For more options, visit this group at  
> [http://groups.google.com/group/rubyonrails-talk?hl=en](http://groups.google.com/group/rubyonrails-talk?hl=en).

–  
Thanks:  
Rajeev sharma

---

<div class="post-metadata">

**Author:** ![gandhi-tush](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/5daacb/32.png) [@gandhi-tush](https://www.ruby-forum.com/u/gandhi-tush)\
**Post date:** [June 7, 2010, 9:18am UTC](https://www.ruby-forum.com/t/model-validation-giving-problem/189757/3 "2010-06-07T09:18:19Z")

</div>

Hi Rajeev,  
I just added the model validations for understanding.

Whatever model validation you have added are same in my model.

Thanks,  
Tushar

---

<div class="post-metadata">

**Author:** ![gandhi-tush](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/5daacb/32.png) [@gandhi-tush](https://www.ruby-forum.com/u/gandhi-tush)\
**Post date:** [June 7, 2010, 9:28am UTC](https://www.ruby-forum.com/t/model-validation-giving-problem/189757/4 "2010-06-07T09:28:56Z")

</div>

Try this in yours model

Validate :password\_confirmation

## def password\_confirmation

* * *

## -----Your Code----------------

* * *

end

On Mon, Jun 7, 2010 at 12:48 PM, Tushar G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> –  
> You received this message because you are subscribed to the Google G.  
> “Ruby on Rails: Talk” group.  
> To post to this group, send email to removed\_email\_address@domain.invalid.  
> To unsubscribe from this group, send email to  
> removed\_email\_address@domain.invalid[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> .  
> For more options, visit this group at  
> [http://groups.google.com/group/rubyonrails-talk?hl=en](http://groups.google.com/group/rubyonrails-talk?hl=en).

–  
Thanks:  
Rajeev sharma
