Can't update user attributes – Rails and Devise-Collection of common programming errors

I am using Rails (3.0.9) with Devise (1.5.3) and I have an User model in which the attributes can’t be updated for some reason I have no idea about.

The form for this User object has many attributes including those from devise: password and password_confirmation, for example.

When I submit the form I get this in the logger:

WARNING: Can't mass-assign protected attributes: current_password

But when I add current_password to attr_accessible I get:

ActiveRecord::UnknownAttributeError at /users unknown attribute: current_password

I am not very into Devise but I think current_password is just a virtual attribute. This error is very annoying, have you any idea on why this is happening? I am clueless.

By the way, my Users::RegistrationsController#update action:

def update
  logger.error "SALMONELLA " + self.resource.password.inspect

  self.resource = resource_class.to_adapter.get!(send(:"current_#{resource_name}").to_key)

  #params[:user].delete [:current_password]

  if resource.update_attributes(params[:user])
    Resque.enqueue(MdcUpdateUser, resource.id)
    set_flash_message :notice, :updated if is_navigational_format?
    sign_in resource_name, resource, :bypass => true
    respond_with resource, :location => after_update_path_for(resource)
  else
    clean_up_passwords(resource)
    respond_with_navigational(resource){ render_with_scope :edit }
  end
end

I’ve tried using Devise’s update_without_password and tried also deleting current_password from the params[:user] hash but had no success.

I appreciate any help you give me. Please ask for any more information if you think there is any information missing in this question.

  1. Then you may have to also add attr_accessor :current_password to your model. Also see the Devise Wiki and this issue for further insight.

Originally posted 2013-11-09 20:20:05.