Skip to content

Commit d71f98f

Browse files
committed
Remove leftover accepts_nested_attributes_for stuff. Ensure all authors/contributors can be removed
1 parent 35e95d6 commit d71f98f

4 files changed

Lines changed: 7 additions & 5 deletions

File tree

app/assets/javascripts/people.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ const People = {
4141
return newForm;
4242
},
4343

44-
// This is just cosmetic. The actual removal is done by rails,
45-
// by virtue of the hidden checkbox being checked when the label is clicked.
4644
delete: function () {
47-
$(this).parents('.person-form').fadeOut();
45+
$(this).parents('.person-form').fadeOut('fast', function() {
46+
$(this).remove();
47+
});
4848
},
4949

5050
init: function () {

app/models/concerns/has_people.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def set_people_for_role(value, role_name, role_key)
2626
current_people = send(role_name).to_a
2727
to_keep = []
2828

29-
value = value.values if value.respond_to?(:keys) && value.keys.first.match(/\A\d+\z/)
29+
value = value.values if value.respond_to?(:keys) && value.keys.first&.match(/\A\d+\z/)
3030
Array.wrap(value).reject(&:blank?).map do |person_data|
3131
person_data = person_data.to_h if person_data.is_a?(ActionController::Parameters)
3232
if person_data.is_a?(String)

app/views/common/_people_form.html.erb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
<%= f.label field_name.to_sym, label, class: 'control-label' %>
1717
<%= f.field_lock(field_name.to_sym) if f.object.respond_to?(:locked_fields) %>
1818
19+
<%# This blank association is needed to trigger the delete when all associations are removed %>
20+
<input type="hidden" name="<%= "#{model_name}[#{field_name}][0]" -%>" value=""/>
21+
1922
<div data-role="people-form-list">
2023
<% f.object.send(field_name).each_with_index do |person, index| %>
2124
<%= render partial: 'common/person_form',

test/controllers/materials_controller_test.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,6 @@ class MaterialsControllerTest < ActionController::TestCase
291291
assert_equal test_material.other_types, JSON.parse(response.body)['other_types'], 'other_types not matched'
292292
#assert_equal test_material.events, JSON.parse(response.body)['events'], 'events not matched'
293293
assert_equal test_material.target_audience, JSON.parse(response.body)['target_audience'], 'target audience not matched'
294-
# Authors is now an array of objects with id, name, orcid
295294
response_authors = JSON.parse(response.body)['authors']
296295
assert_equal test_material.authors.size, response_authors.size, 'authors count not matched'
297296
response_authors.each_with_index do |author_json, i|

0 commit comments

Comments
 (0)