Permalink
Browse files

adding a Student to a 'Homeroom' now assigns the student to that home…

…room
  • Loading branch information...
1 parent 42461ea commit 7cee29cc29fd94fc3873c5b1231ee4188d222c6a @rnhurt committed Aug 24, 2011
Showing with 11 additions and 1 deletion.
  1. +6 −0 app/controllers/courses_controller.rb
  2. +5 −1 app/models/course.rb
@@ -100,6 +100,8 @@ def add_student
students.each do |student|
begin
@course.students << student
+ student.homeroom = @course.name if @course.is_homeroom?
+ student.save!
rescue ActiveRecord::RecordInvalid
# This is here to catch an existing student being added to a course
end
@@ -113,6 +115,10 @@ def add_student
if @course.students.index(@student) == nil
@course.students << @student
@course.save
+
+ # If this course is a homeroom then change this student's homeroom
+ @student.homeroom = @course.name if @course.is_homeroom?
+ @student.save!
end
end
View
@@ -35,7 +35,11 @@ class Course < ActiveRecord::Base
def school_year
return self.terms.first.school_year
end
-
+
+ # Is this a "Homeroom" course?
+ def is_homeroom?
+ self.course_type.is_homeroom?
+ end
private

0 comments on commit 7cee29c

Please sign in to comment.