我的用户模型在/ users / 1 / edit
设置页面目前,您可以更改电子邮件并更改密码(带确认信息)。
我希望有一个名为“current_password”的字段,用户必须先输入当前密码才能更改任何信息。
现在是我的表格: <%= form_for(@ user)do | f | %GT;
<%= render 'shared/error_messages', :object => f.object %>
<div class="field">
<%= f.label :email %><br />
<%= f.text_field :email %>
</div>
<div class="field">
<%= f.label :password %><br />
<%= f.password_field :password %>
</div>
<div class="field">
<%= f.label :password_confirmation, "Confirmation" %><br />
<%= f.password_field :password_confirmation %>
</div>
<div class="actions">
<%= f.submit "Update" %>
</div>
<% end %>
显然,如果我只是添加字段,它会给我一个错误,因为我的用户模型没有“current_password”属性。
我该怎么做?有没有更好的方法呢?
答案 0 :(得分:0)
您可以将其添加到模型和数据库中,也可以将其添加到模型中:
add attr_reader :current_password
然后您可以在模型中对其进行验证。