Sha256: 730363b59c5fd02ec580c6079eeb62aec99e9b69e9a4aa3a3bc1fe3b0bc24310
Contents?: true
Size: 752 Bytes
Versions: 9
Compression:
Stored size: 752 Bytes
Contents
module Volt class UniqueValidator def self.validate(model, old_model, field_name, args) errors = {} if RUBY_PLATFORM != 'opal' if args value = model.read_attribute(field_name) query = {} # Check to see if any other documents have this value. query[field_name.to_s] = value query['_id'] = {'$ne' => model._id} # Check if the value is taken # TODO: need a way to handle scope for unique if $page.store.send(:"_#{model.path[-2]}").find(query).size > 0 message = (args.is_a?(Hash) && args[:message]) || "is already taken" errors[field_name] = [message] end end end errors end end end
Version data entries
9 entries across 9 versions & 1 rubygems