Question

I'm using rails 4.0.1 and ruby 2.0.0 with devise 3.2.2. I keep getting this issue when a user tries to edit his account. I have my strong parameters in application_controller.rb and a custom update controller which looks like this:

class RegistrationsController < Devise::RegistrationsController

def update
    # For Rails 4
    account_update_params = devise_parameter_sanitizer.for(:account_update)
    @user = User.find(current_user.id)
    @user.balanced_associate_token_with_customer(account_update_params)
    if @user.update_with_password(account_update_params)
      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 

protected def after_update_path_for(resource) user_path(resource) end end

I have been pulling my hairs since yesterday...any assitance would be appreciated. Let me know if you need any more info.

Edited: The only thing that changed before i noticed the error is that devise starting asking for config.secret_key in devise initialize file.

A portion of the full trace shows:

devise (3.2.2) lib/devise/models/database_authenticatable.rb:64:in `[]'
devise (3.2.2) lib/devise/models/database_authenticatable.rb:64:in `update_with_password'
app/controllers/registrations_controller.rb:12:in `update'
actionpack (4.0.2) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (4.0.2) lib/abstract_controller/base.rb:189:in `process_action'

Thanks!

Was it helpful?

Solution

I fixed the issue after a number of hours. Hopefully this helps someone out there. Seems Devise changed its documentation. Anyway I removed this line:

account_update_params = devise_parameter_sanitizer.for(:account_update)

and changed this line:

if @user.update_with_password(account_update_params)

to

if @user.update_with_password(devise_parameter_sanitizer.sanitize(:account_update))

Everything works..now I need a drink.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top