小编Mik*_*and的帖子

关注wiki后,在注册编辑中仍然会收到"当前密码不能为空"

我担心这里的解决方案很明显,但我在设计维基上的说明时遇到了问题(https://github.com/plataformatec/devise/wiki/How-To%3a-Allow-users-to-编辑他们的帐户 - 无需提供密码)

我正在使用Rails 4.在关注维基之后,我仍然收到"当前密码不能为空".这是我的设置.非常感谢任何帮助!

REGISTRATIONS_CONTOLLER.rb

class RegistrationsController < Devise::RegistrationsController
  def update
    @user = User.find(current_user.id)

    successfully_updated = if needs_password?(@user, params)
      @user.update_with_password(devise_parameter_sanitizer.for(:account_update))
      # Rails 3:  @user.update_with_password(params[:user])
    else
      # remove the virtual current_password attribute update_without_password
      # doesn't know how to ignore it
      params[:user].delete(:current_password)
      @user.update_with_password(devise_parameter_sanitizer.for(:account_update))
      # Rails 3: @user.update_without_password(params[:user])
    end

    if successfully_updated
      set_flash_message :notice, :updated
      # Sign in the user bypassing validation in case his password changed
      sign_in @user, :bypass => true
      redirect_to after_update_path_for(@user)
    else
      render "edit"
    end
  end

  private
  # …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails devise ruby-on-rails-4

5
推荐指数
1
解决办法
5128
查看次数

标签 统计

devise ×1

ruby-on-rails ×1

ruby-on-rails-4 ×1