DVGM/app/models/grade.rb

17 lines
615 B
Ruby
Raw Normal View History

2017-10-22 18:56:44 +00:00
class Grade < ApplicationRecord
2019-02-21 21:54:26 +00:00
has_one_attached :submission
2017-10-22 18:56:44 +00:00
belongs_to :lecture
belongs_to :student
2019-02-21 21:54:26 +00:00
validates_numericality_of :grade , :less_than_or_equal_to=>100, :greater_than_or_equal_to=>0, :allow_nil => true
2017-10-22 18:56:44 +00:00
validates :lecture, presence: true
validates :student, presence: true
2019-02-21 21:54:26 +00:00
validate :submission_size_validation
def submission_size_validation
if submission.attached?
errors[:grade] << "attachment must be less than 500kB" if submission.blob.byte_size > 500.kilobytes
errors[:grade] << "attachment must be a pdf" if submission.filename.extension != "pdf"
end
end
2017-10-22 18:56:44 +00:00
end