Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added scope for enrollment #31

Merged
merged 1 commit into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading