Skip to content

Commit

Permalink
Added scope for enrollment
Browse files Browse the repository at this point in the history
  • Loading branch information
dalvarez2596 committed Nov 4, 2024
1 parent 32d5684 commit 5c16cb5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
13 changes: 13 additions & 0 deletions app/helpers/courses_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,17 @@ def enrollment_button(course)
link_to "Check price", course_path(course), class: "btn btn-md btn-success"
end
end

def review_button(course)
user_course = course.enrollments.where(user: current_user)
if current_user
if user_course.any?
if user_course.pending_review.any?
link_to "Add a review", edit_enrollment_path(user_course.first)
else
link_to "Thanks for reviewing! Your Review", enrollment_path(user_course.first)
end
end
end
end
end
2 changes: 2 additions & 0 deletions app/models/enrollment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class Enrollment < ApplicationRecord

validate :cant_subscribe_to_own_course

scope :pending_review, -> { where(rating: [ 0, nil, "" ], review: [ 0, nil, "" ]) }

def to_s
user.to_s + " " + course.to_s
end
Expand Down
2 changes: 2 additions & 0 deletions app/views/courses/_course.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
.card-footer
.text-center
= enrollment_button(course)
.row
= review_button(course)
.card-footer
.fa.fa-list-check
= course.lessons.count
Expand Down

0 comments on commit 5c16cb5

Please sign in to comment.