3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/volt/models/validators/unique_validator.rb', line 3
def self.validate(model, old_model, field_name, args)
errors = {}
if RUBY_PLATFORM != 'opal'
if args
value = model.read_attribute(field_name)
query = {}
query[field_name.to_s] = value
query['_id'] = {'$ne' => model._id}
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
|