Class | Student
In: | app/models/student.rb
Parent: | ActiveRecord::Base

### Methods

before_destroy before_update validate

### Public Instance methods

before_destroy()

[Source]

        # File app/models/student.rb, line 12
    12:   def before_destroy()
    13:     # IF THE LAST STUDENT IN A GROUP IS REMOVED, SO WILL ALL GROUP'S GRADES
    14:     # (SAME LOGIC AS INDIVIDUAL GRADES FOR ONE STUDENT)
    15:     group=self.groupnum
    16:     if group > 0
    17:       cnt=Student.count(:conditions => "groupnum = #{group}")
    18:       if cnt == 1
    19:         # THIS IS THE LAST STUDENT IN THE GROUP WHO IS BEING REMOVED
    20:         Ggrade.delete_all(:groupnum => "#{group}")
    21:       end
    22:     end
    23:   end

before_update()

IF A STUDENT IS IN A GROUP THAT HAS GRADED ASSIGNMENT, THE STUDENT CAN NO LONGER SWITCH GROUPS, ALSO IF THE STUDENT TRIES TO SWITCH INTO A GROUP THAT HAS GRADED ASSIGNMENT(S), HE/SHE IS NOT ALLOWED

[Source]

        # File app/models/student.rb, line 29
    29:   def before_update()
    30:       @rec_id = read_attribute(:id)
    31:       group=Student.find(:all, :select => "students.groupnum",
    32:       :conditions => "id = #{@rec_id}").map { |x| x.groupnum }
    33:       if Ggrade.exists?(:groupnum => "#{group}") ||
    34:          Ggrade.exists?(:groupnum => "#{self.groupnum}")
    35:          errors.add_to_base(
    36:          "Either your group has graded assignment(s), or the one you switch into does")
    37:         false
    38:       end
    39:   end

validate()

[Source]

       # File app/models/student.rb, line 3
    3:   def validate
    4:      # THIS WILL ENFORCE THAT BOTH First_Name and Last_Name WILL BE ENTERED
    5:      errors.add_on_empty %w( name user email)
    6:   end

[Validate]