Gene Kahn
2006-Jul-06 17:46 UTC
[Rails] 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: ===================<!--[form:user]--> <p><label for="user_name">Name</label><br/> <%= text_field ''user'', ''name'' %></p> <label for="user_password">Password:</label><br /> <%= text_field :password, :size => 40 %><br /> <label for="user_password_confirmation">Confirm Password:</label><br /> <%= text_field :password_confirmation, :size => 40 %><br /> <!--[eoform:user]--> 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 -- Posted via http://www.ruby-forum.com/.
Brian Hutchison
2006-Jul-29 23:42 UTC
[Rails] Problem implementing password and password confirmation
Did you ever solve this problem? I''ve had something similiar going on. On 7/6/06, Gene Kahn <kublaikhan55@hotmail.com> wrote:> > 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: > ===================> <!--[form:user]--> > <p><label for="user_name">Name</label><br/> > <%= text_field ''user'', ''name'' %></p> > > <label for="user_password">Password:</label><br /> > <%= text_field :password, :size => 40 %><br /> > > <label for="user_password_confirmation">Confirm Password:</label><br /> > <%= text_field :password_confirmation, :size => 40 %><br /> > <!--[eoform:user]--> > > 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 > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060729/d58b5cff/attachment.html