Class: Course::Video::Submission

Inherits:
ApplicationRecord show all
Includes:
NotificationConcern, TodoConcern
Defined in:
app/models/course/video/submission.rb

Defined Under Namespace

Modules: NotificationConcern, TodoConcern Classes: Controller, SessionsController, SubmissionsController

Class Method Summary collapse

Instance Method Summary collapse

Methods included from TodoConcern

#todo

Class Method Details

.by_user(user) ⇒ Object

Finds all the submissions by the given user.


23
# File 'app/models/course/video/submission.rb', line 23

scope :by_user, ->(user) { where(creator: user) }

.ordered_by_dateObject

Orders the submissions by date of creation. This defaults to reverse chronological order (newest submission first).


18
# File 'app/models/course/video/submission.rb', line 18

scope :ordered_by_date, ->(direction = :desc) { order(created_at: direction) }

Instance Method Details

#existing_submissionObject

Finds a submission under the same video and and by the same user


26
27
28
29
30
# File 'app/models/course/video/submission.rb', line 26

def existing_submission
  return nil unless @existing_submission || (video.present? && creator.present?)
  @existing_submission ||=
    Course::Video::Submission.find_by(video_id: video.id, creator_id: creator.id)
end