1
votes

I was reading the documentation on devise on how to allow users to edit their account without password. Follow their first suggestion, I get an

ActiveRecord::RecordInvalid Exception: Validation failed: Password can't be blank, Password confirmation can't be blank

my controller:

class UserPreferencesController < Devise::RegistrationsController

  def update_profile
    @user = User.find(current_user.id)
    if @user.update!(account_params)
      sign_in @user, :bypass
      render json: [], status: 201
    else
      render json: [], status: 422
    end
  end

  def account_params
    params[:user].permit(:first_name, :last_name, :email, :sex, :phone_number, :location, :birthday)
  end

end

I tried the second

def update_resource(resource, params)
  resource.update_without_password(params)
end

Same error. So how do I update the user in devise without password and via json

1
Please update your question with the form code.Pavan

1 Answers

2
votes

Override the password_required? in the model you are updating:

def password_required?
  false
end

That would be enough to edit/update the resource without providing the password.