我正在使用Rails(3.0.9)与Devise(1.5.3),我有一个用户模型,其中的属性由于某种原因无法更新我没有关于的想法。无法更新用户属性 - Rails和Devise
此User对象的表单具有许多属性,例如包括来自devise的密码和password_confirmation。
当我提交表单我得到这个记录器:
WARNING: Can't mass-assign protected attributes: current_password
但是当我添加current_password
到attr_accessible
我得到:
ActiveRecord::UnknownAttributeError at /users unknown attribute: current_password
我不是很成设计但我认为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
我一直在使用设计的update_without_password
试了又试也从params[:user]
哈希删除current_password
,但没有成功。
我感谢你给我的任何帮助。如果您认为此问题中缺少任何信息,请询问更多信息。
你能发布你的用户模型代码和表单代码吗? – 2012-07-10 21:08:48