我正在尝试验证设计生成的表单中是否存在 current_password 字段以编辑用户注册。
注册/edit.html.erb:
<h2>Edit <%= resource_name.to_s.humanize %></h2>
<%= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name), :method => :put, :validate => true) do |f| %>
<%= f.error_notification %>
<div class="form-inputs">
<%= f.input :email, :required => true %>
<% if devise_mapping.confirmable? && resource.pending_reconfirmation? %>
<p>Currently waiting confirmation for: <%= resource.unconfirmed_email %></p>
<% end %>
<%= f.input :password, :autocomplete => "off", :hint => "leave it blank if you don't want to change it", :required => false %>
<%= f.input :password_confirmation, :required => false %>
<%= f.input :current_password, :hint => "we need your current password to confirm your changes", :required => true, :validate => true %>
</div>
<div class="form-actions">
<%= f.button :submit, "Update" %>
</div>
<% end %>
<h3>Cancel my account</h3>
<p>Unhappy? <%= link_to "Cancel my account", registration_path(resource_name), :data => { :confirm => "Are you sure?" }, :method => :delete %></p>
<%= link_to "Back", :back %>
这似乎不起作用。带有空白 current_password 字段的提交将通过并在服务器上进行验证。我不确定在哪里寻找或做什么才能让 client_side_validations 能够处理这个问题。我不确定注册模型在哪里。
仔细研究设计,我发现 current_password 的验证是以我怀疑 client_side_validations 永远不会接受的方式处理的:Devise 中的相关方法。对于这种情况,我觉得我可以在 jquery 中使用一个简单的模糊事件。