我是刚完成 Michael Hartl 的 Rails 学习教程的 Rails 新手。多棒的人啊!
我过去五个小时的生活目标是强制用户输入他们的旧密码,作为用户编辑页面中密码更新过程的一部分。
这是据我所知;
我已将此字段添加到 (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,
这是我收到的当前服务器端错误消息(我已经“用谷歌搜索了错误消息!一百次”)
"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
我的问题是我需要对“def update”进行哪些修改才能包含该current_password
属性!?还有我需要做的任何其他更新吗?
基本上我想做的就是强制用户在用户编辑页面上输入(并确认)新密码之前确认他们的旧密码。
我在哪里错了?
任何帮助表示赞赏!
这是我的github
https://github.com/mwcahn/sample_app
谢谢!