Ruby on rails 更新密码装置

Ruby on rails 更新密码装置,ruby-on-rails,ruby,devise,Ruby On Rails,Ruby,Devise,我的表单中有update\u而不使用\u password方法,但我知道如何在edit\u user\u registration\u path中更新我的密码 我意识到如果我不提供当前密码,我就无法更改密码, 即使不使用密码方法,我也可以在编辑用户表单中更改密码吗 我的注册管理员: def update_resource(resource, params) resource.update_without_password(params) end def after_update

我的表单中有
update\u而不使用\u password
方法,但我知道如何在
edit\u user\u registration\u path
中更新我的密码

我意识到如果我不提供当前密码,我就无法更改密码, 即使不使用密码方法,我也可以在编辑用户表单中更改密码吗

我的注册管理员:

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

  def after_update_path_for(resource)
      biens_path(resource)
  end

这就是我在大多数应用程序中设置用户的方式

在这个模型中,我有一个应该验证密码的方法

# app/models/user.rb
class User < ApplicationRecord
  attr_accessor :updating_password
  ...
  def should_validate_password?
    updating_password || new_record?
  end
  ...
end
#app/models/user.rb
类用户<应用程序记录
属性访问器:更新\u密码
...
def是否应验证密码?
更新|密码|新|记录?
终止
...
终止
现在在控制器中,我有一个before过滤器

# app/controllers/users_controller.rb 
class UsersController < ApplicationController
  before_filter :check_password_submitted, :only => :update
  ...
  private
  def check_password_submitted
    if params[:user][:password].blank?
      params[:user].delete("password")
      params[:user].delete("password_confirmation")
      user.updating_password = false
    else
      user.updating_password = true
    end
  end
  ...
end
#app/controllers/users_controller.rb
类UsersController:update
...
私有的
def检查\u密码\u已提交
如果参数[:用户][:密码]。为空?
参数[:用户]。删除(“密码”)
参数[:用户]。删除(“密码确认”)
user.updateing_password=false
其他的
user.updateing_password=true
终止
终止
...
终止

这就是对我有效的方法

是不是
无密码更新
方法不起作用?你能在问题陈述中清楚地表达出来吗?无密码更新有效,但如果添加它,我无法更改我的密码,因为要更改密码,我需要当前密码字段,我知道在编辑注册中更改密码的方法path WITH be be force以提供当前密码@NIthin感谢您的帮助,您保留了“update_WITH_password”方法?提交表单时无需控制器检查是否有密码,然后更新模型
updating_password
方法