设计Registerable + client_side_validations以验证edit_registration表单

时间:2013-06-16 19:50:21

标签: ruby-on-rails devise client-side-validation

我正在尝试验证Devise生成表单中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会被接受的方式处理的:Relevant methods in Devise。对于这种情况,我觉得我可能会在jquery中使用简单的模糊事件。

0 个答案:

没有答案