File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed
Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments