0

我有一个使用 Devise 和 ClientSideValidations gems 的应用程序。

在下面的表格中,我已经使用设计进行了客户端验证。我认为它正在工作,因为现在无法实际提交表单。我的问题是文本字段标签旁边不会出现任何文本,例如“不能为空白”。知道我做错了什么吗?

%h3 Sign up
%br
= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :validate => true) do |f|
  %h4
    = devise_error_messages!
  %div
    = f.label :name
    = f.text_field :name, :validate => true
  %div
    = f.label :email
    = f.email_field :email, :validate => { :presence => :true }

  %div
    = f.label :password
    = f.password_field :password, :validate => { :presence => :true, :length => true }
  %div
    = f.label :password_confirmation
    = f.password_field :password_confirmation,  :validate => { :presence => true }
  %div
    = f.submit "Sign up", id: 'button'
= render "devise/shared/links"

当我查看源代码时,会出现 js。

<script>//<![CDATA[
if(window.ClientSideValidations==undefined)window.ClientSideValidations={};if(window.ClientSideValidations.forms==undefined)window.ClientSideValidations.forms={};window.ClientSideValidations.forms['new_user'] = {"type":"ActionView::Helpers::FormBuilder","input_tag":"<div class=\"field_with_errors\"><span id=\"input_tag\" /></div>","label_tag":"<div class=\"field_with_errors\"><label id=\"label_tag\" /></div>","validators":{"user[name]":{"presence":[{"message":"can't be blank"}]},"user[email]":{"presence":[{"message":"can't be blank"}]},"user[password]":{"presence":[{"message":"can't be blank"}],"length":[{"messages":{"minimum":"is too short (minimum is 6 characters)","maximum":"is too long (maximum is 128 characters)"},"allow_blank":true,"minimum":6,"maximum":128}]}}};
//]]></script>

所以我知道它在那里,我相信它正在做它的工作,但由于某种原因,当我将一个字段留空时,我只是没有看到我期望的错误消息。

4

0 回答 0