8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/xsdk/scaffold/rails/errors.rb', line 8
def errors
local_errors = super()
keys = self.class.reflect_on_all_associations.select do |assoc|
self.class.nested_attributes_options.key? assoc.name
end
keys.each do |assoc|
name_assoc = assoc.name
local_errors.delete(name_assoc)
model_assoc = send(name_assoc)
next if model_assoc.nil?
row_errors = {}
if assoc.macro == :belongs_to
row_errors[model_assoc._uuid] = model_assoc.errors.messages if model_assoc.errors.messages.keys.any?
else
model_assoc.each do |row|
row_errors[row._uuid] = row.errors.messages if row.errors.messages.keys.any?
end
end
local_errors.add(name_assoc, row_errors) if row_errors.keys.any?
end
local_errors
end
|