简体   繁体   中英

client_side_validations not working with devise + rails 3.2.1

I cannot get things working with client_side_validations and devise. I am using a simple form with email, password and password confirm.

If I tab out of any field, I don't get errors. I only see the server side errors after I submit.

I am using Rails 3.2.1, have followed the steps on the gems github, I am not using formtastic or simple_form. I've un-commented the code from client_side_validations.rb

I've tried the suggestion found here,

Rails 3: client_side_validations gem and devise password validations

Made changes to app/views/devise/registrations/new/html.erb and it is not working for me.

<h2>Register</h2>
<div class="register_form">
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :validate => true) do |f| %>

  <%= devise_error_messages! %>

  <div><%= f.label :email %><br />
  <%= f.email_field :email, :validate => true %></div>

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

  <div><%= f.label :password_confirmation %><br />
  <%= f.password_field :password_confirmation, :validate => true %></div>

  <div><%= f.submit "Sign up" %></div>
<p>
<%= render 'links' %>
</p>
<% end %>
</div>

Moreover I am seeing an error with the password field the odd time. If I type less then 6 letters, tab out, I get an error saying I need to enter at least 6 letters, and one have to be a number? After the error, whatever was typed in the password filed get deleted, if I try to type something the password field keeps getting blanked out!

Happened to me and it seems that client_side_validations 3.1.4 or below isn't compatible with Rails 3.2.1 or above. I was using Rails 3.2.6 so tried beta gem using

gem "client_side_validations", "~> 3.2.0.beta.3"

And it worked, though I am not seeing the error messages.

So I had this same problem just fixed it now, the big issue seems to be with jQuery have you set it up properly? If you inspect your page you should see that jQuery is being included - if not that is the problem right there in which case you need to install the gem for it.

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