1

我最近发布了一个问题,寻求有关如何让 client_side_validations gem 与 Devise 一起使用的帮助。我收到了 gem 的作者的及时回复,尝试使用不同版本的 gem,这暂时解决了我的问题。

但是我现在只能触发电子邮件地址字段。我可以从表单后注入的 javascript 中看到它正在引用表单中的其他字段,但它似乎没有触发任何错误消息。这是我的代码:

宝石文件

gem 'client_side_validations', :github => 'bcardarella/client_side_validations', :branch => '3-2-stable'

用户.rb

  validates :email, :presence => { :message =>  "An email address is required."}, :uniqueness => { :message => "Email address has already been taken."}
  validates :first_name, :presence => { :message => "A first name is required."}
  validates :last_name, :presence => { :message => "A last name is required."}
  validates :privacy_policy, :acceptance => { :message => "Please accept the Privacy policy."}

形式

<h1>Sign up</h1>

<%= link_to(user_omniauth_authorize_path(:facebook), :class => "btn btn-primary btn-fb-large btn-large") do %>
    <div class="icon"><span></span><i class="icon-facebook"></i></div><div class="divider"></div>Sign in with Facebook
<% end %>

<%= form_for(resource, :validate => true, :as => resource_name, :url => registration_path(resource_name)) do |f| %>

  <%= f.label :first_name %>
  <%= f.text_field :first_name, :validate => true %>

  <%= f.label :last_name %>
  <%= f.text_field :last_name, :validate => true %>

  <%= f.label :email %>
  <%= f.email_field :email %>

  <%= f.label :password %>
  <%= f.password_field :password, :validate => true %>

  <%= f.label :password_confirmation %>
  <%= f.password_field :password_confirmation %>

  <%= f.label :privacy_policy, :class => 'checkbox' do %>
  <%= f.check_box :privacy_policy %>I agree to the <%= link_to "Privacy policy", privacy_path %><% end %>

  <%= f.submit "Sign up", :class => 'btn' %>
<% end %>

注入脚本

<script>//<![CDATA[
if(window.ClientSideValidations===undefined)window.ClientSideValidations={};window.ClientSideValidations.disabled_validators=[];window.ClientSideValidations.number_format={"separator":".","delimiter":","};if(window.ClientSideValidations.patterns===undefined)window.ClientSideValidations.patterns = {};window.ClientSideValidations.patterns.numericality=/^(-|\+)?(?:\d+|\d{1,3}(?:\,\d{3})+)(?:\.\d*)?$/;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\" /><label for=\"\" class=\"message\"></label></div>","label_tag":"<div class=\"field_with_errors\"><label id=\"label_tag\" /></div>","validators":{"user[first_name]":{"presence":[{"message":"A first name is required."}]},"user[last_name]":{"presence":[{"message":"A last name is required."}]},"user[email]":{"uniqueness":[{"message":"has already been taken","case_sensitive":true,"allow_blank":true},{"message":"Email address has already been taken.","case_sensitive":true}],"format":[{"message":"is invalid","with":/^[^@\s]+@([^@\s]+\.)+[^@\s]+$/,"allow_blank":true},{"message":"is invalid","with":/^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i}],"presence":[{"message":"An email address is required."}]},"user[password]":{"presence":[{"message":"can't be blank"}],"confirmation":[{"message":"doesn't match confirmation"}],"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}]},"user[privacy_policy]":{"acceptance":[{"message":"Please accept the Privacy policy.","accept":"1"}]}}};
//]]></script>

我已经尝试了可以​​在 Google 上找到的所有搜索结果,并探索了与 Devise 相关的所有途径,但没有运气。

我在浏览器控制台中没有收到 JS 错误。

任何帮助将不胜感激。

4

1 回答 1

0

我在开发一个应用程序时遇到了类似的错误。我认为您应该将您的 rails 版本升级到 3.2.6。它会解决你的问题

于 2013-05-02T12:30:26.890 回答