Client side validations with Devise

天大地大妈咪最大 提交于 2019-12-06 12:00:54

Argc, argv! I am using Rails 3.2.1, the latest release of the gem is incompatible with 3.2 hence the nightmare. Using 3.2.0.beta.2 fixes the problems. Thanks!

Try to put the :validates => true on your fields directly, like this :

<h2>Sign up</h2> 
<hr />

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

  <div>
    <%= f.label :username %>   
    <%= f.text_field :username, :validate => true %>
  </div>

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

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

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

  <br />

  <div>
    <%= f.submit "Sign up", :class => "btn btn-primary btn-large" %>
  </div> 
<% end %>

<%= render "links" %>

change the line

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

to

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

I haven't used client_side_validations gem extensively yet. But from the look of it, it needs to have data-validate="true" in the form (and form elements) tags.

Do you find it in the output html form like:

<form novalidate="novalidate" method="post" data-validate="true" action="/some_actions" >

If you don't find it, you might want to write your form_for like this:

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

Does it help?

To use an stable version use 3.0.3 that was the latest stable version supporting rails 3.2.x

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!