简体   繁体   English

使用Rails 3.2.1设计+ client_side_validations

[英]Devise + client_side_validations using Rails 3.2.1

I posted a recent question asking for help on how to get the client_side_validations gem to work with Devise. 我发布了一个最近的问题,寻求有关如何使client_side_validations gem与Devise一起使用的帮助。 I received a prompt response from the author of the gem, to try a different version of the gem, which temporarily fixed my problem. 我收到了gem的作者的迅速回复,尝试使用其他版本的gem,这暂时解决了我的问题。

However I can now only trigger the email address field. 但是,我现在只能触发电子邮件地址字段。 I can see from the javascript injected after the form that it is referencing the other fields in the form, but it doesn't seem to trigger any error messages. 我可以从表单后面注入的javascript中看到,它引用了表单中的其他字段,但似乎没有触发任何错误消息。 Here is my code: 这是我的代码:

Gemfile 宝石文件

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

User.rb User.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."}

Form 形成

<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 %>

Injected script 注入脚本

<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>

I have tried every search result I can find on Google and explored every avenue linked to Devise with no luck. 我尝试了所有可以在Google上找到的搜索结果,并尝试了与Devise链接的所有方法。

I am receiving no JS errors in the browser console. 我在浏览器控制台中没有收到JS错误。

Any help would be greatly appreciated. 任何帮助将不胜感激。

I got similar error when developing one application. 开发一个应用程序时出现类似错误。 I think you should upgrade your rails version to 3.2.6. 我认为您应该将Rails版本升级到3.2.6。 It will solve your problems 它将解决您的问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM