Skip to content
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
2 changes: 1 addition & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class ApplicationController < ActionController::Base
before_action :authenticate_user!
protect_from_forgery

after_action :user_activity
after_action :user_activity, if: :user_signed_in?
allow_browser versions: :modern

include Pundit::Authorization
Expand Down
1 change: 1 addition & 0 deletions app/controllers/courses_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class CoursesController < ApplicationController
skip_before_action :authenticate_user!, only: [ :show ]
before_action :set_course, only: %i[ show edit update destroy approve unapprove ]

# GET /courses or /courses.json
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ class HomeController < ApplicationController
def index
@courses = Course.all.limit(4)
@latest_good_reviews = Enrollment.reviewed.latest_good_reviews
@latest = Course.latest
@top_rated = Course.top_rated
@popular = Course.popular
@latest = Course.latest.published.approved
@top_rated = Course.top_rated.published.approved
@popular = Course.popular.published.approved
@purchased = Course.joins(:enrollments).where(enrollments: { user: current_user }).order(created_at: :desc).limit(3)
end

Expand Down
2 changes: 1 addition & 1 deletion app/helpers/courses_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def enrollment_button(course)
link_to "Free", new_course_enrollment_path(course), class: "btn btn-md btn-success"
end
else
link_to "Check price", course_path(course), class: "btn btn-md btn-success"
link_to "Check price", new_course_enrollment_path(course), class: "btn btn-md btn-success"
end
end

Expand Down
20 changes: 18 additions & 2 deletions app/policies/course_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,24 @@
end

def show?
@record.published && @record.approved ||@user.present? && @user.has_role?(:admin) || @user.present? && @record.user_id == @user.id || @record.bought(@user)
end
@record.published && @record.approved || @user.present? && @user.has_role?(:admin) || @user.present? && @record.user_id == @user.id || @user.present? && @record.bought(@user)
end

# another logic for show
# def show?
# # Check if the record is published and approved
# return true if @record.published && @record.approved

Check failure on line 23 in app/policies/course_policy.rb

View workflow job for this annotation

GitHub Actions / lint

Layout/TrailingWhitespace: Trailing whitespace detected.
# # Check user conditions if the user is present
# return true if @user.present? && (
# @user.has_role?(:admin) ||
# @record.user_id == @user.id ||
# @record.bought(@user)
# )

Check failure on line 30 in app/policies/course_policy.rb

View workflow job for this annotation

GitHub Actions / lint

Layout/TrailingWhitespace: Trailing whitespace detected.
# # If none of the conditions are met, return false
# false
# end

def edit?
@record.user == @user
Expand Down
2 changes: 1 addition & 1 deletion app/policies/lesson_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def show?
end

def edit?
@record.course.user_id == @user.id
@user.present? && @record.course.user_id == @user.id
end

def update?
Expand Down
18 changes: 10 additions & 8 deletions app/views/home/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,16 @@
.row
Learn on your schedule

%hr
%h2
.fa.fa-user-graduate
Continue Learning
.row.row-cols-lg-4
- @purchased.each do |course|
.col
= render 'courses/course', course: course

- if current_user
%hr
%h2
.fa.fa-user-graduate
Continue Learning
.row.row-cols-lg-4
- @purchased.each do |course|
.col
= render 'courses/course', course: course
%hr
%h2
.fa.fa-chart-line
Expand Down
Loading