Skip to content

Commit 83c2e5f

Browse files
platbrallanbreyes
authored andcommitted
Fix nested params
1 parent 0ac59d0 commit 83c2e5f

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

lib/activeadmin/resource_dsl.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,25 @@ def json_editor
1515
end
1616
object.attributes = { key => data }
1717
end
18+
object.nested_attributes_options.keys.each {|_nested_key|
19+
nested_attributes_with_index = params[resource_request_name]["#{_nested_key}_attributes"]
20+
next if nested_attributes_with_index.nil?
21+
nested_klass = _nested_key.to_s.singularize.camelize.constantize
22+
nested_klass.columns_hash.select { |_key, attr| attr.type.in? [:json, :jsonb] }.keys.each do |key|
23+
nested_attributes_with_index.each {|_index, nested_attributes|
24+
next unless nested_attributes.key? key
25+
json_data = nested_attributes[key]
26+
data = if json_data == 'null' || json_data.blank?
27+
{}
28+
else
29+
JSON.parse(json_data)
30+
end
31+
object.send(_nested_key).each {|nested_object|
32+
nested_object.attributes = { key => data }
33+
}
34+
}
35+
end
36+
}
1837
end
1938
end
2039
end

0 commit comments

Comments
 (0)