简体   繁体   中英

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. I received a prompt response from the author of the gem, to try a different version of the gem, which temporarily fixed my problem.

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. Here is my code:

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

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.

I am receiving no JS errors in the browser console.

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. It will solve your problems

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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