Search code examples
jqueryruby-on-railsvalidationdeviseclient-side-validation

Client_side_validations gem not working in rails 3.2.13


I've spent quite a while trying to get client_side_validations gem to work, but no text is showing up and no script tags are being injected after the forms. I have tried it with both the standard form generated by Rails and a Devise form. I have made sure to include the rails.validations.js file and uncomment the block within the initialiser supplied with the gem.

Here is my code:

client_side_validations.rb

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

JS include

<%= javascript_include_tag "/javascript/rails.validations.js" %>

Gemfile

gem 'client_side_validations'

Standard rails form

<%= form_for(@report, :validate => true) do |f| %>
<%= f.hidden_field :url, :value => "http://#{request.host}:#{request.port}#{request.fullpath}" %>

<%= f.label :elements %>
<%= f.text_field :elements %>

<%= f.label :comments %>
<%= f.text_area :comments %>

<%= f.submit "Send", :class => 'btn' %>

Devise form

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

  <%= f.label "First name" %>
  <%= f.text_field :first_name %>

  <%= f.label "Last name" %>
  <%= f.text_field :last_name %>

  <%= f.label :email %>
  <%= f.email_field :email %>

  <%= f.label :password %>
  <%= f.password_field :password %>

  <%= 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 %>

I am literally at a loss as to what I can do next. Would I need to reference a different version of the gem? How can I check to see if the gem is actually functioning?

I am currently using Rails 3.2.13

I am not getting any errors in the javascript console.

If you would like to look at the related files, let me know.

Any pointers would be very much appreciated!


Solution

  • Please try the following in your Gemfile:

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