Problem implementing password and password confirmation

Hi,
I’m trying to implement password confirmation, based on the Agile
example, but just can’t make any progress.

User DB has these fields:

  t.column :name, :string, :limit => 40
  t.column :hashed_password, :string
  t.column :salt, :string

User model has:

attr_accessor :password_confirmation
validates_confirmation_of :password

‘password’ is a virtual attribute

def password
@password
end

def password=(pwd)
@password = pwd
create_new_salt
self.hashed_password = User.encrypted_password(self.password,
self.salt)
end

Controller

def create
@user = User.new(params[:user])
if @user.save
flash[:notice] = “User #{@user.name} was successfully created.”
redirect_to :action => ‘new’
else
flash[:notice] = “User #{@user.name} was NOT created.”
render :action => ‘new’
end
end

New view has

<%= start_form_tag :action => ‘create’ %>
<%= render :partial => ‘form’ %>
<%= submit_tag “Create” %>
<% end_form_tag %>

And _form.rhtml has:

Name
<%= text_field 'user', 'name' %>

Password:

<%= text_field :password, :size => 40 %>

Confirm Password:

<%= text_field :password_confirmation, :size => 40 %>

The error message is:

User billy was NOT created.

3 errors prohibited this user from being saved

There were problems with the following fields:

* Password confirmation can't be blank
* Password should be at least 5 characters long
* Password can't be blank

Where did I go wrong?
Thanks for the help!
gk

Did you ever solve this problem? I’ve had something similiar going on.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs