zl程序教程

您现在的位置是:首页 >  后端

当前栏目

rails中validates_confirmation_of验证方法无效的解决办法

方法 of 验证 解决办法 无效 Rails
2023-09-14 08:56:51 时间

    rails的model中提供了很多种自带的验证方法,validates_confirmation_of可以验证变量xxx和xxx_confirmation是否相等;这可以用于验证2遍输入的密码是否一致的情况。但是实际使用中发现上述验证方法貌似没有进行验证;在确认了变量:password和:password_confirmation名称确实没错的情况下,研究了半天,发现还要做一步操作,就是要在controller的user_params的许可中加入:password_confirmation才可以哦:

# Never trust parameters from the scary internet, only allow the white list through.

 def user_params

 params.require(:user).permit(:name, :password, :password_confirmation,\

 :depart, :email, :is_admin, :remark)

 end



【异常解决】postman请求提示Full authentication is required to access this resource 在使用 postman 测试接口时,该接口需要在 Header 中传入 access_token,实际上也在请求的 Header 中添加上了 access_token 参数,但是服务端还是返回401错误码,提示未登录,Full authentication is required to access this resource。
在使用Ajax的时候,你可能遇到莫名其妙的的错误,这时你需要学会使用开发者工具来查看并定位、解决问题。