我发布了一个最近的问题,请求获取有关如何让client_side_validations gem与Devise一起使用的帮助。我收到了宝石作者的快速回复,试用了不同版本的宝石,这暂时解决了我的问题。
但是我现在只能触发电子邮件地址字段。我可以从表单之后注入的javascript看到它引用表单中的其他字段,但它似乎没有触发任何错误消息。这是我的代码:
的Gemfile
gem 'client_side_validations', :github => 'bcardarella/client_side_validations', :branch => '3-2-stable'
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."}
表格
<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错误。
非常感谢任何帮助。
答案 0 :(得分:0)
开发一个应用程序时出现类似错误。 我认为你应该将你的rails版本升级到3.2.6。它将解决您的问题