设备中如何更改没有当前密码的密码?

log*_*esh 4 ruby-on-rails devise ruby-on-rails-3

我使用deviseauthentication和我有一个role为每个用户和我允许与用户admin角色来创建新的用户,我想admin用户能edit the password为用户剩下的,如果他们忘记了自己的密码.但是我无法在编辑中没有当前密码的情况下更改密码.那么我如何允许管理员用户通过编辑用户密码来更改密码,并保存我们对其余值的保存.

e11*_*11s 12

由于update_without_password仍需要current_password更新密码,您必须具有update以下内容:

  def update
    # required for settings form to submit when password is left blank
    if params[:user][:password].blank?
      params[:user].delete("password")
      params[:user].delete("password_confirmation")
    end

    @user = User.find(current_user.id)
    if @user.update_attributes(params[:user])
      set_flash_message :notice, :updated
      # Sign in the user bypassing validation in case his password changed
      sign_in @user, :bypass => true
      redirect_to after_update_path_for(@user)
    else
      render "edit"
    end
  end
Run Code Online (Sandbox Code Playgroud)

此示例用于更新当前用户(包括用户的密码),但您可以根据需要对其进行修改.