我是一位Rails新手,剛剛完成Michael Hartl的Leils教程。真是個好人!Michael Hartl的sample_app用戶編輯current_password編輯
我最近五個小時的生活目標是強制用戶在用戶編輯頁面輸入他們的舊密碼作爲密碼更新過程的一部分。
這就是我所得到的;
我已將此字段添加到(sample_app)edit.html.erb頁面。
<%= f.label :current_password %> <i>(we need your current password to confirm your changes)</i><br />
<%= f.password_field :current_password %>
我也更新user.rb與「current_password」如下
class User < ActiveRecord::Base
attr_accessible :name, :email, :current_password, :password, :password_confirmation,
這是當前服務器端錯誤mesage我得到(我「一派錯誤消息!一百年次)
"ActiveRecord::UnknownAttributeError in UsersController#update
unknown attribute: current_password
Rails.root: /Users/nicolemcnight/rails_projects/sample_app
Application Trace | Framework Trace | Full Trace
app/controllers/users_controller.rb:55:in `update'"
顯然有什麼不對的users_controller,特別是‘高清更新’目前看起來是這樣的;
def update
if @user.update_attributes(params[:user])
flash[:success] = "Profile updated"
sign_in @user
redirect_to @user
else
render 'edit'
end
end
我的問題是什麼改變,我需要做出「高清更新」以包括current_password
屬性!?還有我需要做的其他更新?
基本上,我想要做的就是強制用戶在用戶編輯頁面輸入(並確認)新密碼之前確認其舊密碼。
我在哪裏錯了?
任何幫助表示讚賞!
,這裏是我的github
https://github.com/mwcahn/sample_app
謝謝!
::加載ActiveModel :: MassAssignmentSecurity中的錯誤UsersController#更新 不能大規模指派保護的屬性:current_password – mwcahn 2012-08-05 08:58:28
如果你得到的質量分配錯誤,添加:current_password到attr_accessible爲好。與@ user1559108寫的相反,你不應該在你的數據庫中添加一個current_password字段。您已經保存了用戶的密碼。編寫attr_accessor:current_password將創建一個不受數據庫支持的current_password屬性。沒有理由爲此創建數據庫列,這沒有任何意義。 – 2012-08-05 14:21:42
好的,我銷燬了(rails破壞)current_password字段的添加。我添加了before_update(之前沒有見過)。現在沒有錯誤消息,但沒有任何錯誤消息:(我可以輸入任何我想要的current_password字段。我只是將所有內容都推送到我的github github.com/mwcahn。感謝您的幫助!我感受到了進步! – mwcahn 2012-08-05 18:24:49