Mini John
Mini John

Reputation: 7941

Allow users to edit their account without providing a password | Rails4

In Rails 3 it worked just fine, but with my new Rails4 Appp i don't know whats the problem.

The Guide on the Devise GitHub Page

My Registrations Controller

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

    @user = User.find(current_user.id)
    if @user.update_without_password(devise_parameter_sanitizer.sanitize(:account_update))
        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

My Application Controller

def configure_permitted_parameters
    devise_parameter_sanitizer.for(:sign_up) do |u|
        u.permit(:name, :first_name, :user_name, :email, :password, :password_confirmation, :provider, :uid)
    end
    devise_parameter_sanitizer.for(:account_update) do |u|
        u.permit(:name, :email, :password, :password_confirmation, :first_name, :last_name,
                         :user_name, :avatar, :profile_cover, :facebook_link,
                         :twitter_link, :instagram_link, :status)
    end
end

I added the controller to my Routes

:registrations => "registrations"

And i Changed the update calls using the appropriate method below:

@user.update_without_password(devise_parameter_sanitizer.sanitize(:account_update))

But i'm getting a NoMethodError in RegistrationsController#update Error.

enter image description here

Upvotes: 0

Views: 649

Answers (1)

Mini John
Mini John

Reputation: 7941

I don't know yet if this is a good practice but i changed in my RegistrationsController the update action to

@user.update_attributes(account_update_params)

Upvotes: 1

Related Questions