【问题标题】:Devise update user password without password_confirmation设计没有密码确认的更新用户密码
【发布时间】:2011-12-23 10:46:46
【问题描述】:

我想在没有密码确认的情况下更新用户密码。如果密码字段为空 - 密码不要更改。我怎么能用设计做到这一点? 也许使用 required_pa​​ssword?

【问题讨论】:

    标签: ruby-on-rails authentication devise


    【解决方案1】:

    最新的 rails 6 解决方案:

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

    在您的 registrations_controller.rb 文件中

    【讨论】:

      【解决方案2】:

      不用输入,密码:

        def password_required?
          !persisted? || !password.nil? || !password_confirmation.nil?
        end
      

      https://github.com/plataformatec/devise/blob/master/lib/devise/models/validatable.rb

      字符串 - 49

      【讨论】:

      • 请问这里的答案是什么?不知道如何解释这个
      【解决方案3】:

      【讨论】:

      • 谢谢,但方式不同。当我更改密码时,我不需要再次确认(password_confirmation),但需要当前密码。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多