Search code examples
ruby-on-railsruby-on-rails-3.2rubygemsclient-side-validation

Client_side_validations gem doesn't seem to work at all, Rails 3.2.13


I added client-side-validations to my Gemfile and ran bundle install. Then ran rails g client_side_validations:install

It created config/initializers/client_side_validations.rb (wheres my JS file? the asset pipeline?)

It's supposed to work out've the box but it didn't seem to.

I went to config/initializers/client_side_validations.rb and uncommented the following lines from :

#ClientSideValidations Initializer


# Uncomment to disable uniqueness validator, possible security issue
# ClientSideValidations::Config.disabled_validators = [:uniqueness]

# Uncomment the following block if you want each input field to have the validation messages attached.
# ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
#   unless html_tag =~ /^<label/
#     %{<div class="field_with_errors">#{html_tag}<label for="#{instance.send(:tag_id)}" class="message">#{instance.error_message.first}</label></div>}.html_safe
#   else
#     %{<div class="field_with_errors">#{html_tag}</div>}.html_safe
#  end
# end

to:

#ClientSideValidations Initializer


    # Uncomment to disable uniqueness validator, possible security issue
    # ClientSideValidations::Config.disabled_validators = [:uniqueness]

    # Uncomment the following block if you want each input field to have the validation messages attached.
     ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
       unless html_tag =~ /^<label/
         %{<div class="field_with_errors">#{html_tag}<label for="#{instance.send(:tag_id)}" class="message">#{instance.error_message.first}</label></div>}.html_safe
       else
         %{<div class="field_with_errors">#{html_tag}</div>}.html_safe
       end
     end

I decided to run rails g client_side_validations:copy_assets and then I required rails.validations (//= require rails.validations) in my application.js file (before //= require tree .).

When I try to tab out of form fields no inline errors are displayed, when I submit a form no errors are displayed either.

I have the following code for my form and model:

class User < ActiveRecord::Base
  has_secure_password
  attr_accessible :email, :password, :password_confirmation
  validates_presence_of :email
  validates_presence_of :password, :on => :create
  validates_length_of :password, :minimum => 6
  validates_confirmation_of :password
  validates_uniqueness_of :email
end

<h1>Sign Up</h1>

<%= form_for User.new, :validate => true do |f| %>
    <p>
      <%= f.label :email %>
      <%= f.text_field :email %>
    </p>
    <p>
      <%= f.label :password %>
      <%= f.password_field :password %>
    </p>
    <p>
      <%= f.label :password_confirmation %>
      <%= f.password_field :password_confirmation %>
    </p>
    <p>
      <%= f.submit "Sign Up" %>
    </p>
<% end %>

I'm hoping the problem is in my configuration or syntax and not with the gem.

Any insight would be fully appreciated.


Solution

  • Use 3-2-stable on your Gemfile, and run bundle install

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