# Validates\_confirmation\_of not working

**URL:** <https://www.ruby-forum.com/t/validates-confirmation-of-not-working/52933>\
**Category:** Rails\
**Created:** [January 20, 2006, 5:20pm UTC](https://www.ruby-forum.com/t/validates-confirmation-of-not-working/52933 "2006-01-20T17:20:08Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![adamdorsey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ed8c4c/32.png) [@adamdorsey](https://www.ruby-forum.com/u/adamdorsey)\
**Post date:** [January 20, 2006, 5:20pm UTC](https://www.ruby-forum.com/t/validates-confirmation-of-not-working/52933/1 "2006-01-20T17:20:08Z")

</div>

is there any special requirement for validates\_confirmation\_of ? I am  
trying to make sure 2 passwords are equal (cleanly the rails way)…

In my view i have two fields with id user[password] and  
user[password\_confirmation].

in the model i have

validates\_confirmation\_of :password, :message =\>"Passwords do not match  
"

Am i missing something here ?

thanks  
adam

---

<div class="post-metadata">

**Author:** ![adamdorsey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ed8c4c/32.png) [@adamdorsey](https://www.ruby-forum.com/u/adamdorsey)\
**Post date:** [January 20, 2006, 5:31pm UTC](https://www.ruby-forum.com/t/validates-confirmation-of-not-working/52933/2 "2006-01-20T17:31:30Z")

</div>

This is what I have and works good

in my view  
\<%= text\_field “user”, “password”%\>  
\<%= text\_field “user”, “password\_confirmation”%\>

and in my model  
validates\_confirmation\_of :password

and in controller

def register  
if request.method == :post  
@user = User.new(params[:user])  
if @user.save  
session[:user] = @user  
redirect\_to :controller =\> “mynerve”  
end  
else  
@user = User.new  
end  
end

So what exactly does not work?

Regards  
Gokhan A.  
[www.sylow.net](http://www.sylow.net)

---

<div class="post-metadata">

**Author:** ![adamdorsey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ed8c4c/32.png) [@adamdorsey](https://www.ruby-forum.com/u/adamdorsey)\
**Post date:** [January 20, 2006, 5:41pm UTC](https://www.ruby-forum.com/t/validates-confirmation-of-not-working/52933/3 "2006-01-20T17:41:22Z")

</div>

if i put in 2 different passwords it just continues without an error.  
I cant figure out why.

adam

---

<div class="post-metadata">

**Author:** ![adamdorsey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ed8c4c/32.png) [@adamdorsey](https://www.ruby-forum.com/u/adamdorsey)\
**Post date:** [January 29, 2006, 2:37am UTC](https://www.ruby-forum.com/t/validates-confirmation-of-not-working/52933/4 "2006-01-29T02:37:45Z")

</div>

In your model, add this:

validates\_confirmation\_of :password (assuming your column is named  
password)

In your view.rhtml: (assuming your model is named user)

\<%= password\_field ‘user’, ‘password’ %\>  
\<%= password\_field ‘user’, ‘password\_confirmation’ %\>

If you have it like this, then something else is funky.

Bob S.  
[http://www.railtie.net/](http://www.railtie.net/)

---

<div class="post-metadata">

**Author:** ![adamdorsey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ed8c4c/32.png) [@adamdorsey](https://www.ruby-forum.com/u/adamdorsey)\
**Post date:** [January 29, 2006, 2:22am UTC](https://www.ruby-forum.com/t/validates-confirmation-of-not-working/52933/5 "2006-01-29T02:22:25Z")

</div>

I’m having the same problem

Adam D. wrote:

> if i put in 2 different passwords it just continues without an error.  
> I cant figure out why.
> 
> adam

---

<div class="post-metadata">

**Author:** ![adamdorsey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ed8c4c/32.png) [@adamdorsey](https://www.ruby-forum.com/u/adamdorsey)\
**Post date:** [January 29, 2006, 3:30am UTC](https://www.ruby-forum.com/t/validates-confirmation-of-not-working/52933/6 "2006-01-29T03:30:17Z")

</div>

Sorry, that first sentence should read

“Well, I’m hashing and storing the password in the  
hashed\_password column just like the Depot application in the Agile  
book.”

---

<div class="post-metadata">

**Author:** ![adamdorsey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ed8c4c/32.png) [@adamdorsey](https://www.ruby-forum.com/u/adamdorsey)\
**Post date:** [January 29, 2006, 3:27am UTC](https://www.ruby-forum.com/t/validates-confirmation-of-not-working/52933/7 "2006-01-29T03:27:58Z")

</div>

Well, I’m storing hashing and storing the password in the  
hashed\_password column just like the Depot application in the Agile  
book. And since validates\_confirmation\_of is only checking :password  
against :password\_confirmation, this should be strictly a naming  
problem, right?

Bob S. wrote:

> In your model, add this:
> 
> validates\_confirmation\_of :password (assuming your column is named  
> password)
> 
> In your view.rhtml: (assuming your model is named user)
> 
> \<%= password\_field ‘user’, ‘password’ %\>  
> \<%= password\_field ‘user’, ‘password\_confirmation’ %\>
> 
> If you have it like this, then something else is funky.
> 
> Bob S.  
> [http://www.railtie.net/](http://www.railtie.net/)

---

<div class="post-metadata">

**Author:** ![adamdorsey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ed8c4c/32.png) [@adamdorsey](https://www.ruby-forum.com/u/adamdorsey)\
**Post date:** [January 29, 2006, 5:35am UTC](https://www.ruby-forum.com/t/validates-confirmation-of-not-working/52933/8 "2006-01-29T05:35:25Z")

</div>

the issue i had was not following the rails standard in the views.  
Once i changed everything to the

\<%= text\_field ‘user’ , ‘password’ %\> setup so everything got passed  
in as @params[:user] it worked ok. The issue was i was just  
submitting it as @params[:password] originally and not  
@params[:user][“password”]

adam

---

<div class="post-metadata">

**Author:** ![adamdorsey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ed8c4c/32.png) [@adamdorsey](https://www.ruby-forum.com/u/adamdorsey)\
**Post date:** [January 29, 2006, 4:14am UTC](https://www.ruby-forum.com/t/validates-confirmation-of-not-working/52933/9 "2006-01-29T04:14:09Z")

</div>

Does your model have ‘password’ as an attribute since its not in the  
table?

attr :password

And don’t forget to protect your attributes.

attr\_protected :hashed\_password

Bob S.  
[http://www.railtie.net/](http://www.railtie.net/)
