SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    Jan 2006
    Posts
    268
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Change Password Page

    I have a change password page in my app, so users can change their password. This page was working fine a few days ago, and I'm not sure what I changed, but now it is giving me validation errors. (outlined below)

    Here are my pages:
    user.rb
    Code:
      validates_confirmation_of :password
      validates_length_of :password, :minimum => 6
    user_controller.rb
    Code:
        def changepass
        if request.post? #form submitted
          @user.update_attributes(params[:user])
          if @user.save
            flash[:notice] = "Password Successfully Changed"
          end  
        end
      end
    user/changepass.rhtml
    Code:
          <form id="changepass" action="" method="post">
          <fieldset>
            <legend>New Password</legend>
            <label for="user_password">New Password:</label><%= password_field("user", "password")%>
            <label for="user_password_confirmation">Confirm Password:</label><%= password_field("user", "password_confirmation", {:value => ""}) %>
            <input type="submit" class="submit" value="  Change Password  "/>
        </form>
    When I leave the textfields blank I get:
    1 error, --> Password must be at least 6 characters.
    When I put in a 6+ character password in both boxes (they match):
    2 errors --> Password must be at least 6 characters and Password confirmation does not match password.

    I do have a before_create method, in user.rb, that auto-assigns a password for when the account is created, could this be the problem? I would think that would only get called on a new user, not updating a current one.

    Any ideas?
    If you give someone a program,
    you will frustrate them for a day;
    if you teach them how to program,
    you will frustrate them for a lifetime.

  2. #2
    SitePoint Enthusiast kyko's Avatar
    Join Date
    May 2006
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is what the action should look like:

    Code:
    def changepass
      if request.post? #form submitted
        @user = User.find(params[:id])
        if @user.update_attributes(params[:user])
          flash[:notice] = "Password Successfully Changed"
        end  
      end
    end
    Stop Global &nbsp;


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •