From 049ae4548fd53f4a3b1290813b2b6d4b8856900d Mon Sep 17 00:00:00 2001 From: rebuilt Date: Sat, 8 Apr 2023 14:49:21 -0700 Subject: [PATCH] Don't add another response rate record to the database. Just calculate on the fly. Otherwise we can run into a situation where we create two response rates for a given school/academic_year/subcategory --- app/models/subcategory.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/subcategory.rb b/app/models/subcategory.rb index ae4767db..9bbe7da0 100644 --- a/app/models/subcategory.rb +++ b/app/models/subcategory.rb @@ -26,8 +26,8 @@ class Subcategory < ActiveRecord::Base def create_response_rate(school:, academic_year:) student = StudentResponseRateCalculator.new(subcategory: self, school:, academic_year:) teacher = TeacherResponseRateCalculator.new(subcategory: self, school:, academic_year:) - ResponseRate.create(school:, academic_year:, subcategory: self, student_response_rate: student.rate, - teacher_response_rate: teacher.rate, meets_student_threshold: student.meets_student_threshold?, - meets_teacher_threshold: teacher.meets_teacher_threshold?) + ResponseRate.new(school:, academic_year:, subcategory: self, student_response_rate: student.rate, + teacher_response_rate: teacher.rate, meets_student_threshold: student.meets_student_threshold?, + meets_teacher_threshold: teacher.meets_teacher_threshold?) end end