Forum: Ruby on Rails validates_confirmation_of not working

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
F15fdc7cb2e911b3808837f2be244add?d=identicon&s=25 Adam Denenberg (Guest)
on 2006-01-20 17:20
(Received via mailing list)
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
54077fb03c95861af85880218cf7aef2?d=identicon&s=25 Gokhan Arli (sylow)
on 2006-01-20 17:31
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 Arli
www.sylow.net
F15fdc7cb2e911b3808837f2be244add?d=identicon&s=25 Adam Denenberg (Guest)
on 2006-01-20 17:41
(Received via mailing list)
if i put in 2 different passwords it just continues without an error.
I cant figure out why.

adam
C8134e7a4b73fc95b52114d7dba8971b?d=identicon&s=25 mofo mofo (boram)
on 2006-01-29 02:22
I'm having the same problem

Adam Denenberg wrote:
> if i put in 2 different passwords it just continues without an error.
> I cant figure out why.
>
> adam
Af93ba6b6b59f22a8f37e8de5702ef98?d=identicon&s=25 Bob Silva (Guest)
on 2006-01-29 02:37
(Received via mailing list)
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 Silva
http://www.railtie.net/
C8134e7a4b73fc95b52114d7dba8971b?d=identicon&s=25 mofo mofo (boram)
on 2006-01-29 03:27
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 Silva 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 Silva
> http://www.railtie.net/
C8134e7a4b73fc95b52114d7dba8971b?d=identicon&s=25 mofo mofo (boram)
on 2006-01-29 03:30
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."
Af93ba6b6b59f22a8f37e8de5702ef98?d=identicon&s=25 Bob Silva (Guest)
on 2006-01-29 04:14
(Received via mailing list)
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 Silva
http://www.railtie.net/
F15fdc7cb2e911b3808837f2be244add?d=identicon&s=25 Adam Denenberg (Guest)
on 2006-01-29 05:35
(Received via mailing list)
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
This topic is locked and can not be replied to.