私は、Michael Hartl の学習用 Rails チュートリアルを終えたばかりの Rails 初心者です。なんて素晴らしい男だ!
この 5 時間の私の目標は、ユーザー編集ページでパスワード更新プロセスの一環として、ユーザーに古いパスワードを入力させることでした。
これは私が得た限りです。
このフィールドを (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 %>
また、以下のように「current_password」で user.rb を更新しました
class User < ActiveRecord::Base
attr_accessible :name, :email, :current_password, :password, :password_confirmation,
これは、私が取得している現在のサーバー側のエラー メッセージです (エラー メッセージを 100 回ググってみました)。
"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」です。
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
私の質問は、属性を含めるために「def update」にどのような変更を加える必要があるかです!? 他に必要な更新はありますか?
基本的に、ユーザー編集ページで新しいパスワードを入力 (および確認) する前に、古いパスワードを確認するようユーザーに強制するだけです。
ここでどこが間違っていますか?
どんな助けでも大歓迎です!
ここに私のgithubがあります
https://github.com/mwcahn/sample_app
ありがとう!