Rails 3 - 设计:如何在编辑注册时跳过“current_password"? [英] Rails 3 - Devise : How to skip the 'current_password' when editing a registration?

查看:32
本文介绍了Rails 3 - 设计:如何在编辑注册时跳过“current_password"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经用我的设计模型实现了 omniauth,所以我可以使用其他服务进行身份验证.我的模型不再需要密码,因为用户可以使用 twitter、facebook 进行身份验证...

I've implemented omniauth with my devise model, so I can authenticate using other services. Password is not necessary anymore for my model, as users can authenticate using twitter, facebook...

一切正常,但是,当用户尝试编辑其注册时,设计跳过该过程,因为用户没有通知current_password"(现在在某些情况下不存在).

Everything is working fine, but, when an user try to edit its registration, devise skip the process because the user did not inform the 'current_password' (which doesnt exist in some cases now).

我创建了一个注册控制器来覆盖设计:

I created a registration controller to overwrite the devises one:

class RegistrationsController < Devise::RegistrationsController
  def update
    super
  end
end

但是我没有找到任何关于如何跳过密码验证的文档,我该如何在更新操作中做到这一点?

But I haven't find any documentation about how to skip the password verification, how could I do it in my update action?

推荐答案

与上面类似,尝试将其放入您的用户模型中:

Similar to above, try putting this in your user model:

# bypasses Devise's requirement to re-enter current password to edit
def update_with_password(params={}) 
  if params[:password].blank? 
    params.delete(:password) 
    params.delete(:password_confirmation) if params[:password_confirmation].blank? 
  end 
  update_attributes(params) 
end

这篇关于Rails 3 - 设计:如何在编辑注册时跳过“current_password"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆