问题
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