app/models/student_membership.rb
# Raises an error if this user already has an accepted membership for a different grouping for this assignment
Raises an error if this user already has an accepted membership for a different grouping for this assignment
Raises an error if this user already has an accepted membership for a different grouping for this assignment
def one_accepted_per_assignment
    return unless role.try(:student?)
    all_memberships = role.accepted_memberships
                          .joins(:grouping)
                          .where('groupings.assessment_id': grouping.assessment_id)
    return if all_memberships.empty? || all_memberships.find_by(id: self.id)
    errors.add(:base, :memberships_not_unique)
    throw(:abort)
  end
def one_accepted_per_assignment return unless role . try ( :student? ) all_memberships = role . accepted_memberships . joins ( :grouping ) . where ( 'groupings.assessment_id' : grouping . assessment_id ) return if all_memberships . empty? || all_memberships . find_by ( id : self . id ) errors . add ( :base , :memberships_not_unique ) throw ( :abort ) end
Raises an error if this user already has an accepted membership for a different grouping for this assignment
Raises an error if this user already has an accepted membership for a different grouping for this assignment