Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby User Authentication with Rails Password Resets and Testing Integration Testing Forgotten Passwords

Bug in the update method of the password_reset_controller?

Dear Jason,

I ran in my password_reset_controller

   def update
      @user = User.find_by(password_reset_token: params[:id])
      if @user && @user.update_attributes(user_params)
      @user.update_attribute(:password_reset_token, nil)
      session[:user_id] = @user.id
      redirect_to todo_lists_path, success: "Password updated."
  else
     flash.now[:notice] = "Password reset token not found."
     render action: 'edit'
  end
end

And when I went to reset the password, it would always result in "Password reset token not found."

But when I changed it to

 def update
   @user = User.find_by(password_reset_token: params[:id])
   if @user
       @user.update_attributes(user_params)
       @user.update_attribute(:password_reset_token, nil)
       session[:user_id] = @user.id
       redirect_to todo_lists_path, success: "Password updated."
  else
     flash.now[:notice] = "Password reset token not found."
      render action: 'edit'
  end
end

It works fine. This makes no sense to me.

if @user && @user.update_attributes(user_params)......

is perfectly good ruby.

Anyone any answers about this?

Best

Simon