0

I want to do email confirmation, after having set up sign in/sign up and sessions using the has_secure_password and authenticate method. I have a user model, and I added a confirmed boolean. When a user is created, I set their confirmed boolean to false, and send them an email with a link. Clicking the link generates a GET request to /users/:id/confirm, and executes the code of "confirm" action in the users_controller that is the following :


def confirm
    @user = User.find(params[:id])
    @user.update_attributes(confirmed: true)
    if @user.save 
      sign_in(@user)
      flash[:success] = "Your account has been successfully confirmed"
    else
      flash[:error] = "There has been a problem confirming your account "
    end 
     redirect_to root_path
  end

Very simple (I will do verification token later). My problem is that my user is never saved.

@user.errors.full_messages
returns :

["Password is too short", "Password confirmation can't be blank"]

How can I change a user object without having to edit their password each time ? Any help would be greatly appreciated.

Thanks !

1 Answer 1

1

Try using update_attribute instead of update_attributes.

  @user.update_attribute(:confirmed, true)
Sign up to request clarification or add additional context in comments.

1 Comment

...and don't save twice. update_attribute already does saving -- no need to call @user.save. Remove the latter and check the result of update_attribute instead.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.