-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from dalvarez2596/lessons60-65
Lessons60-65
- Loading branch information
Showing
12 changed files
with
92 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
class LessonPolicy < ApplicationPolicy | ||
# NOTE: Up to Pundit v2.3.1, the inheritance was declared as | ||
# `Scope < Scope` rather than `Scope < ApplicationPolicy::Scope`. | ||
# In most cases the behavior will be identical, but if updating existing | ||
# code, beware of possible changes to the ancestors: | ||
# https://gist.github.com/Burgestrand/4b4bc22f31c8a95c425fc0e30d7ef1f5 | ||
|
||
class Scope < ApplicationPolicy::Scope | ||
# NOTE: Be explicit about which records you allow access to! | ||
# def resolve | ||
# scope.all | ||
# end | ||
end | ||
|
||
def show? | ||
@user.has_role?(:admin) || @record.course.user == @user.id | ||
end | ||
|
||
def edit? | ||
@record.course.user_id == @user.id | ||
end | ||
|
||
def update? | ||
@record.course.user_id == @user.id | ||
end | ||
|
||
def new? | ||
end | ||
|
||
def create? | ||
end | ||
|
||
def destroy? | ||
@record.course.user_id == @user.id | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,16 @@ | ||
-# frozen_string_literal: true | ||
= simple_form_for(@lesson) do |f| | ||
= simple_form_for([@course, @lesson]) do |f| | ||
= f.error_notification | ||
= f.error_notification message: f.object.errors[:base].to_sentence if f.object.errors[:base].present? | ||
|
||
.form-inputs | ||
= f.input :title | ||
= f.input :content | ||
= f.association :course | ||
= f.label :content | ||
= f.rich_text_area :content | ||
-# como estaba | ||
-# = f.association :course | ||
-# Esto de abajo asigno el input del html por defecto si ya es un lesson o por params. as: :hidden hide the input | ||
-# = f.input :course_id, input_html: {value: @course.id || params[:course_id]}, as: :hidden | ||
.form-actions | ||
= f.button :submit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
.card | ||
.card-header | ||
= link_to lesson.title, lesson | ||
.card-body | ||
= lesson.content | ||
= lesson.course | ||
.card-footer | ||
= link_to 'Edit', edit_lesson_path(lesson), class: 'btn btn-sm btn-warning' | ||
= link_to 'Destroy', lesson, data: { turbo_method: :delete, confirm: 'Are you sure' }, class: 'btn btn-sm btn-danger' | ||
= link_to lesson.title, [@course, lesson] | ||
- if policy(lesson).show? | ||
.card-body | ||
= lesson.content | ||
= lesson.course | ||
- if policy(lesson).edit? | ||
.card-footer | ||
= link_to 'Edit', edit_course_lesson_path(@course, lesson), class: 'btn btn-sm btn-warning' | ||
= link_to 'Destroy', [@course, lesson], data: { turbo_method: :delete, confirm: 'Are you sure' }, class: 'btn btn-sm btn-danger' | ||
%p | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ | |
|
||
= render 'form' | ||
|
||
= link_to 'Back', lessons_path | ||
= link_to 'Back', course_path(@course) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
%p#notice= notice | ||
= link_to 'Courses', courses_path | ||
\/ | ||
= link_to @lesson.course.title, course_path(@course) | ||
\/ | ||
= link_to @lesson.title, course_lesson_path(@course, @lesson) | ||
|
||
= render 'lessons/lesson', lesson: @lesson | ||
|
||
= link_to 'Back to course', course_path(@lesson.course) | ||
= link_to 'Back to course', course_path(@course) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters