无法更新用户属性 - Rails和Devise

rod*_*ves 4 ruby activerecord ruby-on-rails devise

我正在使用Rails(3.0.9)和Devise(1.5.3),我有一个用户模型,其中的属性由于某些我不知道的原因无法更新.

此User对象的表单有许多属性,例如来自devise:password和password_confirmation的属性.

当我提交表单时,我在记录器中得到了这个:

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

但是当我加入时current_password,attr_accessible我得到:

ActiveRecord::UnknownAttributeError at /users unknown attribute: current_password

我不是很熟悉Devise,但我认为current_password只是一个虚拟属性.这个错误非常烦人,你知道为什么会这样吗?我很无能为力.

顺便说一下,我的Users::RegistrationsController#update行动:

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
Run Code Online (Sandbox Code Playgroud)

我尝试过使用Devise,update_without_password并试图current_passwordparams[:user]哈希中删除但没有成功.

我感谢你给我的任何帮助.如果您认为此问题中缺少任何信息,请询问更多信息.

man*_*ire 7

然后,您可能还需要添加attr_accessor :current_password到您的模型中.另请参阅 Devise Wiki此问题以获得进一步的见解.