ruby-on-rails – 无法更新用户属性 – Rails和Devise
我正在使用Rails(3.0.9)与Devise(1.5.3),我有一个用户模型,其中的属性由于某些我不知道的原因无法更新.
此User对象的表单有许多属性,例如来自devise:password和password_confirmation的属性. 当我提交表单时,我在记录器中得到了这个: 警告:无法批量分配受保护的属性:current_password 但是当我将current_password添加到attr_accessible时,我得到: / users处的ActiveRecord :: UnknownAttributeError 我不是很熟悉Devise,但我认为current_password只是一个虚拟属性.这个错误非常烦人,你知道为什么会这样吗?我很无能为力. 顺便说一句,我的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 我尝试过使用Devise的update_without_password,并尝试从params [:user]哈希中删除current_password,但没有成功. 我感谢你给我的任何帮助.如果您认为此问题中缺少任何信息,请询问更多信息. 解决方法
然后,您可能还需要将attr_accessor:current_password添加到模型中.另请参阅
Devise Wiki和
this issue以获得进一步的见解.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |