2017-09-25 64 views
0

我有我的表格update_without_password方法,但我会知道如何更新我的密码在我的edit_user_registration_path更新密码设计

我意识到我不能更改我的密码,如果我不给我当前的密码, 即使使用update_wothout_password方法,我可以更改我的edit_user_form中的密码吗?

我登记控制器:

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

    def after_update_path_for(resource) 
     biens_path(resource) 
    end 
+0

是'不工作update_without_password'方法? – Nithin

+0

你能在问题陈述中清楚地表达出来吗? – Nithin

+0

update_without_password工作,但如果添加它,我不能改变我的密码,因为要更改密码,我需要当前密码字段我会知道一种方法来更改密码在编辑注册路径,而不是强制给出当前密码@Nithin –

回答

1

这是我如何我的用户设置在大多数我的应用程序

在模型中我有should_validate_password的方法?

# app/models/user.rb 
class User < ApplicationRecord 
    attr_accessor :updating_password 
    ... 
    def should_validate_password? 
    updating_password || new_record? 
    end 
    ... 
end 

现在,在控制器我有一个过滤器之前

# 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 

,这对我来说是什么工作

+0

感谢你的帮助,你保持“update_without_password”方法? –

+0

当表单提交时,控制器检查是否有密码,然后更新模型'updating_password'方法 – MZaragoza