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

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

问题描述

我已经用我的设计模型实现了全能,所以我可以使用其他服务进行身份验证。
我的模型不需要密码,因为用户可以使用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 - Devise:编辑注册时如何跳过'current_password'?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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