ruby on rails devise skip validation of password, when edit user in user form

17.10 Muhamad Akbar Bin Widayat 0 Comments



If you want to skip password validation in devise login. In users controller, you only add line below:


sign_in @user, :bypass => true unless params[:user][:password].blank?

for example:
def update
    if @user.update_user_data(params[:user])
      sign_in @user, :bypass => true unless params[:user][:password].blank?
      if current_user.is_admin?
        redirect_to users_path
      else
        redirect_to edit_user_path(current_user)
      end
    else
      render :action => :edit
    end
  end



0 komentar:

terimakasih komentarnya