2012-07-10 66 views
4

我正在使用Rails(3.0.9)與Devise(1.5.3),我有一個用戶模型,其中的屬性由於某種原因無法更新我沒有關於的想法。無法更新用戶屬性 - Rails和Devise

此User對象的表單具有許多屬性,例如包括來自devise的密碼和password_confirmation。

當我提交表單我得到這個記錄器:

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

但是當我添加current_passwordattr_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,但沒有成功。

我感謝你給我的任何幫助。如果您認爲此問題中缺少任何信息,請詢問更多信息。

+0

你能發佈你的用戶模型代碼和表單代碼嗎? – 2012-07-10 21:08:48

回答

7

然後您可能還需要將attr_accessor :current_password添加到您的模型中。另請參閱Devise Wikithis issue瞭解更多信息。

相關問題