From fa53e42912729789a52594d6ac985182b6d52b82 Mon Sep 17 00:00:00 2001 From: Iain McNulty Date: Wed, 29 May 2024 14:03:10 +0100 Subject: [PATCH] Ordering the subject ids correctly --- .../publish/courses/modern_languages_controller.rb | 6 ++---- app/controllers/publish/courses/subjects_controller.rb | 2 -- app/models/course.rb | 2 +- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/app/controllers/publish/courses/modern_languages_controller.rb b/app/controllers/publish/courses/modern_languages_controller.rb index 3d887dc5d4..1b20db3587 100644 --- a/app/controllers/publish/courses/modern_languages_controller.rb +++ b/app/controllers/publish/courses/modern_languages_controller.rb @@ -22,7 +22,7 @@ def continue def edit authorize(provider) - return if selected_non_language_subjects_ids.include? modern_languages_subject_id.to_s + return if selected_non_language_subjects_ids.include? modern_languages_subject_id redirect_to( details_publish_provider_recruitment_cycle_course_path( @@ -87,9 +87,7 @@ def selected_subjects(param_key) ids = params.dig(:course, param_key)&.map(&:to_i) || [] - @course.edit_course_options[edit_course_options_key].filter_map do |subject| - subject.id.to_s if ids.include?(subject.id) - end + ids.intersection(@course.edit_course_options[edit_course_options_key].map(&:id)) end def selected_language_subjects_ids diff --git a/app/controllers/publish/courses/subjects_controller.rb b/app/controllers/publish/courses/subjects_controller.rb index c661a1db20..307732cd45 100644 --- a/app/controllers/publish/courses/subjects_controller.rb +++ b/app/controllers/publish/courses/subjects_controller.rb @@ -57,8 +57,6 @@ def update else @errors = @course.errors.messages - # Set attributes to populate the form - course.master_subject_id, course.subordinate_subject_id = selected_subject_ids render :edit end end diff --git a/app/models/course.rb b/app/models/course.rb index 641e08204f..937b633dd5 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -27,7 +27,7 @@ class Course < ApplicationRecord self.master_subject_id ||= sub.first&.subject&.id - self.subordinate_subject_id ||= sub&.second&.subject&.id + self.subordinate_subject_id = sub&.second&.subject&.id end end