Devise: Update Account without password confirmation

左心房为你撑大大i 提交于 2019-12-25 08:42:01

问题


I know that on Devise wiki pages they explain how to do it here: https://github.com/plataformatec/devise/wiki/How-To:-Allow-users-to-edit-their-account-without-providing-a-password

But I am new at Rails(4) and I am trying to do it for hours but I keep receiving the "password can't be blank message'. Can anyone explain how o do it for rails 4?

Updated: here is my code, I create a file in controllers called Registrations with this code:

class RegistrationsController < Devise::RegistrationsController
  def update
    # For Rails 4
    account_update_params = devise_parameter_sanitizer.sanitize(:account_update)
    # For Rails 3
    # account_update_params = params[:user]

    # required for settings form to submit when password is left blank
    if account_update_params[:password].blank?
      account_update_params.delete("password")
      account_update_params.delete("password_confirmation")
    end

    @user = User.find(current_user.id)
    if @user.update_attributes(account_update_params)
      set_flash_message :notice, :updated
      # Sign in the user bypassing validation in case their password changed
      sign_in @user, :bypass => true
      redirect_to after_update_path_for(@user)
    else
      render "edit"
    end
  end
end

And in my routes/config I put this:

devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks", :registrations => "registrations" }

I didn't understand what else I have to do...

来源:https://stackoverflow.com/questions/24463479/devise-update-account-without-password-confirmation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!