Rails 3: client_side_validations throws a warning about starting a unique check

I am using the client_side_validations gem to do form validation in rails 3.

everything works fine except when firefox / ie throws a javascript warning when a unique ajax check is executed and returns a 404 error message.

The author says that record 404 was not found and therefore unique;

Can I handle this.

I opened this at: https://github.com/bcardarella/client_side_validations/issues/297

+5
source share
2 answers

The error you see is that the remote check cannot find the resource on the server. It is expected that if a resource is not found, the resource is unique.

, , , , , , . ClientSideValidations , 2xx. .

+5

, , , , , , 404 ajax.

. , . , , javascript, - , . , HTTP 204 , ClientSideValidations , HTTP 200 ( 200) javascript.

/Config//client_side_validations.rb

ClientSideValidations::Config.disabled_validators = []

# Monkey Patch

# Guranatee uniqueness middleware is fully loaded
::ClientSideValidations::Middleware::Uniqueness

module ClientSideValidations
  module Middleware
    class Uniqueness
      def response
        begin
          if unique?
            self.status = 204 # changed from 404
            self.body   = '' # changed from true
          else
            self.status = 200
            self.body   = 'false'
          end
        rescue NotValidatable
          self.status = 500
          self.body = ''
        end
        super
      end
    end
  end
end
0

All Articles