diff --git a/app/models/olympia_school_data_fields.rb b/app/models/olympia_school_data_fields.rb index da8b34a..7933924 100644 --- a/app/models/olympia_school_data_fields.rb +++ b/app/models/olympia_school_data_fields.rb @@ -21,9 +21,9 @@ class OlympiaSchoolDataFields field :email , type: String , default: '' field :enrollment , type: Fixnum , default: 0 field :approved , type: Boolean , default: true - field :sign_up_setting_id , type: String , default: SignUpSetting.last.id.to_s + field :sign_up_setting_id , type: String , default: SignUpSetting.where(:active=>true).last.id.to_s after_destroy do |record| - OlympiaStudentDataField.where(:olympia_school_data_fields_id => record.id,:sign_up_setting_id=>SignUpSetting.last.id).destroy_all + OlympiaStudentDataField.where(:olympia_school_data_fields_id => record.id,:sign_up_setting_id=>SignUpSetting.where(:active=>true).last.id).destroy_all end after_initialize do if !self.new_record? @@ -36,7 +36,7 @@ class OlympiaSchoolDataFields self.save! end if self.enrollment == 0 #check enrollment student number - self.enrollment = OlympiaStudentDataField.where(:olympia_school_data_fields_id=>self.id,:sign_up_setting_id=>SignUpSetting.last.id).length + self.enrollment = OlympiaStudentDataField.where(:olympia_school_data_fields_id=>self.id,:sign_up_setting_id=>SignUpSetting.where(:active=>true).last.id).length self.save! end if self.enrollment_limited.nil? @@ -44,7 +44,7 @@ class OlympiaSchoolDataFields self.save! end if self.sign_up_setting_id.nil? - self.sign_up_setting_id = SignUpSetting.last.id.to_s + self.sign_up_setting_id = SignUpSetting.where(:active=>true).last.id.to_s self.save! end sign_up_setting = SignUpSetting.find(self.sign_up_setting_id) rescue nil diff --git a/app/models/sign_up_setting.rb b/app/models/sign_up_setting.rb index a826cdc..1f39744 100644 --- a/app/models/sign_up_setting.rb +++ b/app/models/sign_up_setting.rb @@ -39,6 +39,7 @@ class SignUpSetting if self.active SignUpSetting.where.not(:id=>self.id).each do |setting| setting.active = false + setting.save! end end end