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
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
if i put in 2 different passwords it just continues without an error.
I cant figure out why.
adam
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/
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
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.”
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/
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
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/